首页 > 解决方案 > 来自 SDWebImage 的 `sd_setImage` 导致的内存泄漏

问题描述

let path = Bundle.main.path(forResource: deviceGuideGif, ofType: "gif")!
let url:URL = URL.init(fileURLWithPath: path)
imageView.sd_setImage(with: url, completed: nil)

我将此代码添加到 viewController(我们称之为 VC1)。当我从其他viewController推送VC1时,内存使用增加了。之后,我弹出VC1并且内存使用没有减少。现在有内存泄漏,我不知道这是怎么发生的。这是错误的使用方式SDWebImage还是 SDWebImage 中有任何错误?

内存使用

PS:

如果我使用此代码,它会很好地工作:

let path = Bundle.main.path(forResource: deviceGuideGif, ofType: "gif")!
let url:URL = URL.init(fileURLWithPath: path)
let imageData = try?Data.init(contentsOf: url)
let image = UIImage.sd_image(with: imageData)
imageView.image = image

标签: iosswift

解决方案


推荐阅读