当我运行仪器时,我在下一行得到了内存链接
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest
returningResponse:&urlResponse error:&error];
谁能解释一下如何解决这个问题,
谢谢 山姆。
- (NSString *)sendHttpsReqNSString *) urlString {
// create the request
NSString *endResult = nil;
NSURL *posHostUrl = [NSURL URLWithString:urlString];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:posHostUrl
cachePolicy:NSURLCacheStorageAllowed
timeoutInterval:300.0];
// create the connection with the request
// and start loading the data
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[posHostUrl host]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
NSHTTPURLResponse* urlResponse = nil;
//NSError *error = [[NSError alloc] init];
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&urlResponse error:&error];
endResult = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//[error release];
} else{
//Inform the user that the connection failed.
NSLog(@"CONNECTION FAILED");
}
[theConnection release];
return [endResult autorelease];
}
你实际上是在启动 两个 NSURLConnections。一个异步,一个同步。这可能会导致泄漏。
第一个 URLConnection 在该行开始:
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
第二个 URLConnection 在该行开始:
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&urlResponse error:&error];
请确保您只下载一次资源。
关于ios - 为 NSURLConnection 识别出内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3340972/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |