OGeek|极客世界-中国程序员成长平台

标题: ios - iOS 中的最佳图像缓存策略 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:58
标题: ios - iOS 中的最佳图像缓存策略

在我的应用程序中,我有一个 UITableView,它显示相当大的图像并加载一个设计适中的 Xib 文件来显示它。每个图像大约 700KB 到 1MB尺寸。流程几乎永无止境,随着我们向下滚动,它会加载越来越多。所以你可以想象我遇到了内存问题。

我尝试过使用 SDImageCacheNSCache。前者使用磁盘内存来缓存图像。在这两种情况下,缓存都不会自动清除图像。当我收到 Received memory warning 提示时,我不得不手动清除它们。每次我清除这些缓存时,释放的内存似乎每次都更少。

现在我很困惑对于这么长的图像列表我必须使用哪种缓存策略。我可能在某处有泄漏吗?当我分析应用程序时,它们当然没有出现。

P.S.:我正在从网络加载图像。只是为了清楚。



Best Answer-推荐答案


来自文档:

UIImage 

+(UIImage *)imageNamedNSString *)name

Discussion 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.

所以我想把这个留给 UIImage 类是一个好方法。

希望这会有所帮助!

关于ios - iOS 中的最佳图像缓存策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19040265/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4