views:

368

answers:

1

Any idea why sendSynchronousRequest is causing a leak below? Instruments states that the responsible frame is NSURLConnection and it points at a NSCFString leaked in the line with sendSynchronousRequest.

I've read that this was a known issue before OS 2.2 or something, but should definitely be fixed now. Any thoughts?

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

NSURL *url = [NSURL URLWithString:@"http://www.mysite.com/api/v1/dosomething"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0];
[request setHTTPMethod:@"POST"];

NSData *bodyData;

[request setValue:@"text/plain" forHTTPHeaderField:@"Content-Type"];

NSString *body = @"test";
bodyData = [body dataUsingEncoding:NSUTF8StringEncoding];

[request setHTTPBody:bodyData];
[body release]; 

[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];

NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
+1  A: 

I have the same problem in my project. I write a new method, and this method makes asynchrousRequest. After that I call the method like this; performSelector.... waitUntilDone:YES . It worked for me, at least leaks are decreased.

EEE
I've debated trying this... Good to know if I do take this approach it will work.
marcc