gpt4 book ai didi

ios - PNG 图像从未解除分配

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:02:35 25 4
gpt4 key购买 nike

内存调试仍然很痛苦。我使用导航 Controller 加载了 4 个 VC。每个 VC 都有自己的用于多个控件的 PNG 图像。在 Instruments 中,我意识到大部分 VM 区域都被 ImageIO_PNG_Data 占用。当我推送/弹出 VC 时,那些 VM 会增加并且永远不会减少(我假设 dealloc 一些 VC 也会释放图像)。 enter image description here

当然,调试是在Simulator中完成的。

最佳答案

稍微扩展一下 rokjarc 的评论:

UIImage +imageNamed:显式缓存。文档指出:

This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.

因此之前加载的图像将保留在缓存中,除非或直到其他地方需要内存。不必要地释放内存不会提高效率。

如果你出于任何原因想要避免缓存——我会争论任何虚假的原因——你可以使用 +imageWithContentsOfFile: ,或正常的 init 等价物,已从 NSBundle 获得完整路径.

据我所知,通过界面构建​​器设置为 ImageView 和其他位置的 PNG 将通过缓存访问。

关于ios - PNG 图像从未解除分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20790043/

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