ios - 为 NSURLConnection 识别出内存泄漏
<p><p>当我运行仪器时,我在下一行得到了内存链接</p>
<pre><code>NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest
returningResponse:&urlResponse error:&error];
</code></pre>
<p>谁能解释一下如何解决这个问题,</p>
<p>谢谢
山姆。</p>
<pre><code>- (NSString *)sendHttpsReq:(NSString *) urlString {
// create the request
NSString *endResult = nil;
NSURL *posHostUrl = ;
NSURLRequest *theRequest=[NSURLRequest requestWithURL:posHostUrl
cachePolicy:NSURLCacheStorageAllowed
timeoutInterval:300.0];
// create the connection with the request
// and start loading the data
];
NSURLConnection *theConnection=[ 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 = [ init];
NSError *error= nil;
NSData *responseData = ;
endResult = [ initWithData:responseData encoding:NSUTF8StringEncoding];
//;
} else{
//Inform the user that the connection failed.
NSLog(@"CONNECTION FAILED");
}
;
return ;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你实际上是在启动 <strong>两个</strong> NSURLConnections。一个异步,一个同步。这可能会导致泄漏。</p>
<p>第一个 URLConnection 在该行开始:</p>
<pre><code>NSURLConnection *theConnection=[ initWithRequest:theRequest delegate:self];
</code></pre>
<p>第二个 URLConnection 在该行开始:</p>
<pre><code>NSData *responseData = ;
</code></pre>
<p>请确保您只下载一次资源。</p></p>
<p style="font-size: 20px;">关于ios - 为 NSURLConnection 识别出内存泄漏,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/3340972/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/3340972/
</a>
</p>
页:
[1]