我无法在此代码中找到错误:
-(void)downloadImageFromURL:(NSURL*)url withCompletionBlock:(RSSMessageImageDownloadCompletionBlock)completionBlock
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
__block RSSMessage *_self = self;
request.completionBlock =
^{
__block NSData *responseData = request.responseData;
dispatch_async( dispatch_get_main_queue(), ^{
_self.image = responseData;
[[[UIApplication sharedApplication] delegate] saveContext];
if(completionBlock != nil)
{
completionBlock();
}
});
};
[request startAsynchronous];
}
在这种形式中,我从仪器中得到了内存泄漏。我假设这是因为我之前缺少 __block 关键字: ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
但是当我将这个关键字添加到上面的行时,我得到了如下错误:
* -[NSConcreteMutableData isNSData__]:消息发送到已释放实例 0xdeab380
我不知道如何保留请求数据并且不泄漏内存。