gpt4 book ai didi

ios - MPMediaItemPropertyArtwork 导致崩溃(奇怪的问题)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:39:55 24 4
gpt4 key购买 nike

运行“额外循环”之前的分配 allocations before running 'crashing' loop

代码:

// 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.
}

运行“额外循环”后的分配 allocations before running 'crashing' loop

并澄清一下,在 only-obj-c 打开和系统库关闭的情况下调用堆栈(如果我打开它们,每个最重的方法的最高百分比是 0.9%) call stack after extra loop

我做了一些研究,并在 stackoverflow 找到了,这些 VM:ImageIO_PNG_Data 通常来自 [UIImage imageNamed:],但是如您所见,我不使用此方法,我只是获取引用来自 MPMediaItemCollection

最佳答案

问题是 UIImage 通常只保留一个 ref(CGImageRef),它很小。显示项目后,CGImageRef 被“注入(inject)”了信息。结果,该表一直在增长。

简单但不是最漂亮的解决方案是使用代码:

NSArray = @[obj1, obj2, obj3]; // where obj is custom NSObject and has a UIImage property

代替:

NSArray = @[img1, img2, img3]; // where img is of UIImage type

关于ios - MPMediaItemPropertyArtwork 导致崩溃(奇怪的问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19182495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com