gpt4 book ai didi

ios - 在 setImage : 上分配的大量内存

转载 作者:行者123 更新时间:2023-12-01 18:57:36 28 4
gpt4 key购买 nike

我有一个以编程方式创建的 UIImageView ([[UIImageView alloc] init])。应用程序的内存一直受到检查,直到 setImage:方法被调用。有什么想法吗?

最佳答案

我假设您正在使用以下方式将图像设置为 ImageView :

[imgV setImage:[UIImage imageNamed:@"yourImg.png"]]

使用它的问题是应用程序 缓存 这些图像。如果您想避免缓存图像,请使用 imageWithContentsOfFile: :
[imgV setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"yourImg.png" ofType:nil]]];

另外,请务必将您的图像设置为 nil当你完成使用它时:
[imgV setImage:nil];

我过去曾遇到过这个问题,以下是我从 Apple 回复 TSI 的电子邮件中的一些文本:

There are quite a few cases where you’re using the API UIImage +imageNamed: to load images but you should be aware that imageNamed caches its image data even after the returned UIImage object is released. Replacing calls to imageNamed with -imageWithContentsOfFile: as outlined below is a way to ensure full control over your app’s image data in memory

关于ios - 在 setImage : 上分配的大量内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25559990/

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