知道为什么sendSynchronousRequest
导致泄漏?文书指出,负责框架为NSURLConnection
,并指向NSCFString
与sendSynchronousRequest
一行泄露的[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];
。
我已经读过这是OS 2.2之前的一个已知问题,但现在肯定应该修复。有什么想法吗?
{{1}}
答案 0 :(得分:1)
我的项目遇到了同样的问题。我写了一个新方法,这个方法使得asynchrousRequest。之后,我这样称呼方法; performSelector .... waitUntilDone:是的。它对我有用,至少泄漏量减少了。