以下代码来自苹果提供的LazyTableImages示例代码(源代码在此处)。
在它们的完成块中,他们引用了self,这应该会导致保留循环……但我在Xcode中没有收到此警告,而在我的类似代码中,我会收到警告。
这是正确的吗?
也许我错过了这个细节。
在它们的完成块中,他们引用了self,这应该会导致保留循环……但我在Xcode中没有收到此警告,而在我的类似代码中,我会收到警告。
这是正确的吗?
也许我错过了这个细节。
- (void)startIconDownload:(AppRecord *)appRecord forIndexPath:(NSIndexPath *)indexPath
{
IconDownloader *iconDownloader = [self.imageDownloadsInProgress objectForKey:indexPath];
if (iconDownloader == nil)
{
iconDownloader = [[IconDownloader alloc] init];
iconDownloader.appRecord = appRecord;
[iconDownloader setCompletionHandler:^{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
// Display the newly loaded image
cell.imageView.image = appRecord.appIcon;
// Remove the IconDownloader from the in progress list.
// This will result in it being deallocated.
[self.imageDownloadsInProgress removeObjectForKey:indexPath];
}];
[self.imageDownloadsInProgress setObject:iconDownloader forKey:indexPath];
[iconDownloader startDownload];
}
}
self
拥有imageDownloadsInProgress
,它拥有iconDownloader
,后者拥有其completionHandler
,该处理程序对@Abizern
强引用了self
。这里存在一个保留循环。它可能不是一个问题,但确实存在。 - jscs