Cocoa touch UIImage图像存在数据泄漏(GCD)
您好,我收到一份报告,仪表泄漏,代码如下Cocoa touch UIImage图像存在数据泄漏(GCD),cocoa-touch,memory-leaks,uiimage,nsautoreleasepool,grand-central-dispatch,Cocoa Touch,Memory Leaks,Uiimage,Nsautoreleasepool,Grand Central Dispatch,您好,我收到一份报告,仪表泄漏,代码如下 dispatch_async(requestQueue, ^{ NSURL *urlRequest = [NSURL URLWithString:url]; NSError *error = nil; NSData *imageData = [NSData dataWithContentsOfURL:urlRequest
dispatch_async(requestQueue, ^{
NSURL *urlRequest = [NSURL URLWithString:url];
NSError *error = nil;
NSData *imageData = [NSData dataWithContentsOfURL:urlRequest
options:0
error:&error];
if (error != nil)
{
NSLog(@"%@ %@", [error localizedDescription], [error localizedFailureReason]);
[[[[UIAlertView alloc] initWithTitle:[error localizedDescription]
message:[error localizedFailureReason]
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil] autorelease] show];
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
image = [UIImage imageWithData:imageData];
if (delegate != nil && [delegate respondsToSelector:@selector(imageRequestDone:)])
{
[delegate imageRequestDone:image];
}
});
});
Leaks报告my image=[UIImage imageWithData:imageData]泄漏,知道原因吗?
是否需要为自动释放的UIImage对象创建NSAutoreleasePool
顺便说一句,如果有问题的话,我声明uu block UIImage*image=nil;因为在输入上述代码之前,我在ImageCache中检查图像。您尚未释放队列:
dispatch\u release(requestQueue)代码>嗨,谢谢你的建议。但这没用。但是当我回到家时,我在自己的电脑上运行了我的代码,仪器没有报告泄漏?也许是仪器的问题?工作了一段时间后,我根本无法运行泄漏,其他人也有同样的问题吗?泄漏“轨迹”变为黄色。