Charlou
Charlou

Reputation: 3

Leak with HttpRequest Method - Objective-c

I was Analyze my app for searching any leak, and here we are with a "Potential leak of an object stored into replyString". I tried every release than I could, but nothing change, so I'm here asking for some help.

I make this method in my WebService Class.

-(NSString *)httpRequest{

NSData *postData = [self dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:adresse]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *replyString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding: NSASCIIStringEncoding];
return replyString;
}

Thanks :)

Upvotes: 0

Views: 86

Answers (1)

graver
graver

Reputation: 15213

You are creating the replyString with alloc init which means replyString needs to be released, therefore:

return [replyString autorelease];

Upvotes: 2

Related Questions