嗨,我收到来自 Instrument 的报告泄漏,代码如下。
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 报告我的 image = [UIImage imageWithData:imageData] 泄漏,有什么想法吗?对于自动释放的 UIImage 对象,我需要一个 NSAutoreleasePool 吗?
顺便说一句,如果有关系,我声明了 __block UIImage *image = nil; 上面是因为我在输入上面的代码之前检查了 ImageCache 中的图像。