菜鸟教程小白 发表于 2022-12-12 14:58:14

ios - iOS 中的最佳图像缓存策略


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

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

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

<p>P.S.:我正在从网络加载图像。只是为了清楚。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>来自文档:</p>

<blockquote>
<pre><code>UIImage

+(UIImage *)imageNamed:(NSString *)name
</code></pre>

<p>Discussion This method looks in the system caches for an image object
with the specifiedname and returns that object if it exists. If a
matching image object is notalready in the cache, this method loads
the image data from the specified file,caches it, and then returns
the resulting object.</p>
</blockquote>

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

<p>希望这会有所帮助!</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - iOS 中的最佳图像缓存策略,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/19040265/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/19040265/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - iOS 中的最佳图像缓存策略