我在以下使用GCD的代码中有泄漏。注意:我没有使用ARC。泄漏正好在
__block NSMutableArray *newImages = [NSMutableArray new];
dispatch_async(serialQueue, ^{
for (NSDictionary *imageData in results) {
NSURL *url = [NSURL URLWithString:[imageData objectForKey:@"url"]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSError *error = nil;
NSHTTPURLResponse *response = nil;
NSData *imageData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error == nil && imageData != nil && response.statusCode == 200) {
UIImage *image = [UIImage imageWithData:imageData];
[newImages addObject:image];
}
else {
self.errorLabel.text = @"An error has occured downloading some images.";
[self.spinner stopAnimating];
}
}
});
根据文书,我正在泄漏:[newImages addObject:image];
。为什么会泄漏? newImages
是一个自动释放的对象,如上所示。