0

I am getting Potential leak in postdata(NSData- below code ) error.

Can anyone please tell me how to solve these issues? also I saw memory leak in my code [Using the build and analyze of XCode]:

NSUserDefaults *defaults   = [NSUserDefaults standardUserDefaults];
NSString *SessionId        = [defaults objectForKey:@"SessionId"];
NSString *versionid       = [appdetails objectForKey:@"versionId"] ;


NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];

[request setHTTPMethod:@"POST"];
Unnati
  • 2,441
  • 17
  • 37
Suppry
  • 81
  • 1
  • 9
  • 1. Are you using ARC? 2. Where is the static analyzer suggesting that there is A memory leak? – Lefteris Apr 10 '13 at 08:38
  • for use POST method best Example http://stackoverflow.com/questions/15377212/get-the-password-from-the-webservices-url-and-access-through-that-password/15377242#15377242 – iPatel Apr 10 '13 at 08:45

1 Answers1

0

Anything that you alloc (allocate) memory for needs to be released, unless you are using ARC. Try this:

Replace

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];

With

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

The second piece of code creates an autoreleased object so you dont need to release it manually.

JDx
  • 2,615
  • 3
  • 22
  • 33