我正在分析(泄漏)我的应用程序(ARC),它显示了几个我无法弄清楚的内存泄漏。
一个对象(ArchivingTasksManager)启动一个在for循环中创建许多NSOperations的方法,并将它们添加到队列中。每个NSOperation都是一个自定义子类(DownloadImageOperation),我用NSURL实例化。
在ArchivingTasksManager中:
AccountId Name Active Users Forms
1 Child T 3 4
5 Child2 F 4 3
在DownloadImageOperation中:
- (void)archiveAllImages
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self beginBackgroundTask];
[self archiveImages];
});
}
- (void)archiveImages
{
self.queue.suspended = true;
self.queue.maxConcurrentOperationCount = 1;
for (Highlight *highlight in self.list.highlights) {
for (Experience *experience in highlight.experiences) {
for (NSURL *imageURL in [experience allImageURLsOfType:ExperienceImageType640x640]) {
DownloadImageOperation *experienceImageDownload = [[DownloadImageOperation alloc] initWithImageURL:imageURL];
[self.queue addOperation:experienceImageDownload];
}
NSURL *authorURL = [NSURL URLWithString:experience.author.image_250x250Url];
if (authorURL) {
DownloadImageOperation *authorImageDownload = [[DownloadImageOperation alloc] initWithImageURL:authorURL];
[self.queue addOperation:authorImageDownload];
}
}
MapSnapshotOperation *mapSnapshot = [[MapSnapshotOperation alloc] initWithHighlight:highlight];
[self.queue addOperation:mapSnapshot];
}
[self.queue addObserver:self
forKeyPath:NSStringFromSelector(@selector(operationCount))
options:NSKeyValueObservingOptionInitial context:nil];
self.totalOperations = self.queue.operationCount;
self.queue.suspended = false;
}
以下是仪器在ArchivingTasksManager中显示的内容:
以下是Instruments在DownloadImageOperation中显示的内容: