Open lixiang1994 opened 6 years ago
暂时解决方案: 避免使用disk缓存, 使用.fromMemoryCacheOrRefresh
try this
KingfisherManager.shared.cache.maxMemoryCost = 30 * 1024
You can use Kingfisher.AnimatedImageView
instead of UIImageView
to improve memory usage.
@xspyhack Thanks.
animatedFrames load all images in memory and play,how AnimatedImageView impove memory usage? @xspyhack AnimatedImageView improve memory usage? @onevcat
@stackJolin AnimatedImageView
only keeps a limited number of frames in memory, it uses CADisplayLink
to update the buffer asynchronously. For more details, you can read the source code.
复现场景: 创建一个UICollectionView, 一页可显示10个cell, 每个cell中有一个UIImageView, cellForRow代理中为cell中的imageView setImage, (相同的url) gif图片大小大约在3MB左右, 相等于为不同UIImageView同时setImage 10次, 通过回调得知 cacheType为 disk, 此时内存可以飙升300MB. 如果cacheType为 memory 则不会出现这种情况.
猜测: 在disk读取数据时 memory中并没有缓存, disk读取完成写入memory后, memory中才会有缓存记录, 同时在disk没有读取完成前 多次调用setImage(), 造成多次执行disk读取写入内存的操作, 最终导致内存暴涨.
希望可以尽快解决