开发者

Leaks reporting issue with NSURLConnection sendSynchronousRequest

开发者 https://www.devze.com 2022-12-21 23:42 出处:网络
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 sendSynchronousReques

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:&er开发者_如何学Cror];
NSString *responseString = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消