gpt4 book ai didi

ios - 使用 Kingfisher 的 Swift iOS 照片采集会导致内存增长

转载 作者:行者123 更新时间:2023-11-30 12:18:45 27 4
gpt4 key购买 nike

我有一个使用 UICollectionView 的照片浏览应用程序,我使用 Kingfisher 从如下网址下载图像:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
...
cell.ivPhoto.kf.setImage

我使用 xCode Profile 工具进行调试,发现当我滚动 Collection View 时,内存由于这个对象而不断增长:ImageIO_jpeg_Data,并且它链接到 Kingfisher。有时,当滚动浏览包含大图像(每个图像大约 500KB)的 Collection View 时,它非常滞后,内存可能会达到 500+MB 并且应用程序崩溃,我在 lldb 中看到这是内存问题。我尝试这样设置:

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
ImageCache.default.clearMemoryCache()
}

但它并没有解决崩溃问题。

最佳答案

很老的问题,但它可以帮助别人。 Kingfisher 默认具有无限的内存缓存限制。只需将其设置为您想要的值即可。

KingfisherManager.shared.cache.maxMemoryCost = 1000000

希望这有帮助。

关于ios - 使用 Kingfisher 的 Swift iOS 照片采集会导致内存增长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45075939/

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