运行“额外循环”之前的分配
编码:
// loading items to the array, there are no memory warnings after this is completed. The first allocations screenshot is after this code and before extra loop code.
NSMutableArray *albumCovers = [[NSMutableArray alloc] init];
for (MPMediaQuery *query in queries) {
NSArray *allCollections = [query collections];
for (MPMediaItemCollection *collection in allCollections) {
MPMediaItemArtwork *value = [collection.representativeItem valueForProperty:MPMediaItemPropertyArtwork];
UIImage *image = [value imageWithSize:CGSizeMake(100, 100)];
if (image) {
[albumCovers addObject:image];
}
}
}
}
_mediaCollections = [NSArray arrayWithArray:artworkedCollections];
_albumCovers = [NSArray arrayWithArray:albumCovers];
}
在其他地方:
// !!!!! extra loop - from here the memory starts to grow and never release
for (i=0; i< 800; i++) {
UIImage * coverImage = [_albumCovers objectAtIndex:indexPath.row];
[veryTemp setImage:coverImage]; // exactly this line adds to the memory. with this line commented, there is no problem.
}
运行“额外循环”后的分配
并澄清一下,在 only-obj-c 和系统库关闭的情况下调用堆栈(如果我打开它们,最高百分比是每个最重方法的 0.9%)
我进行了一些研究,并在stackoverflow发现这些VM:ImageIO_PNG_Data
通常来自[UIImage imageNamed:]
,但是如您所见,我不使用此方法,我只是从MPMediaItemCollection
.