UIImageView - 实际内存使用量不断增加

发布于 2025-01-07 07:02:22 字数 381 浏览 2 评论 0原文

我有一个 UIImageView,用于在不同时间点显示不同的图像。当我想更改显示的图像时,我使用以下代码(其中 filenamePng 保存要加载的图像名称,imgView 是我的 UIImageView):

    [self.imgView setImage:[UIImage imageNamed:filenamePng]];

当我在 Instruments 中查看应用程序的“实际内存使用情况”时,因为不同的图像是显示后,内存继续增加(有些 png 非常大,因此很容易分辨),我尝试将 UIImageView 设置为 nil/释放它,但无济于事。

有人可以告诉我为什么在使用上面的代码时,即使设置为 nil/released,内存中的先前图像也不会被释放?

I have one UIImageView that I use to display different images at different points in time. When I want to change the image displayed I use the following code (where filenamePng holds the image name to be loaded and imgView is my UIImageView):

    [self.imgView setImage:[UIImage imageNamed:filenamePng]];

When I look at the 'Real Memory Usage' of my app in Instruments, as different images are displayed, the memory just continues to increase (some of the png's are quite large so its easy to tell), I have played around with setting the UIImageView to nil/releasing the it but to no avail.

Can someone give me an indication as to why when using the above code it appears that previous images in memory are not released even when set to nil/released?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏辞 2025-01-14 07:02:22

+[UIImage imageNamed:] 使用缓存。假设所有引用计数都是正确的,它应该在某个时候被清除。此外,在这方面,SIM 与设备上的执行可能会有很大不同。

+[UIImage imageNamed:] uses a cache. Assuming all your ref counting is correct, it should purge at some point. Also, the execution on sim vs device can be much different in this regard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文