我使用SDImageCache从表视图缓存图像,但是当向下滚动时,内存不断增加。所以我检查了库并在SDImageCache.h中找到了属性来设置maxMemoryCost并期望缓存将被删除超过此限制。 但在我的测试中,[SDImageCache sharedImageCache]不会删除任何内容。所以这个房产目前什么也没做。
应用程序最终会因巨大的内存大小而崩溃。
由于
答案 0 :(得分:0)
您好我遇到了同样的问题并修复了我的AppDelegate
didFinishLaunchingWithOptions
方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
SDWebImageDownloader.shared().shouldDecompressImages = false
SDImageCache.shared().shouldDecompressImages = false
}
这应该可以解决问题,这里建立了https://github.com/SDWebImage/SDWebImage/issues/1544#issuecomment-423445538
SDImageCache.shared().config.maxCacheAge = 3600 * 24 * 7 //1 Week
SDImageCache.shared().maxMemoryCost = 1024 * 1024 * 20 //Aprox 20 images
//SDImageCache.shared().config.shouldCacheImagesInMemory = false //Default True => Store images in RAM cache for Fast performance
SDImageCache.shared().config.shouldDecompressImages = false
SDWebImageDownloader.shared().shouldDecompressImages = false
SDImageCache.shared().config.diskCacheReadingOptions = NSData.ReadingOptions.mappedIfSafe
希望这可以帮助你,让我知道
答案 1 :(得分:0)
对我来说,清除内存缓存可以解决此问题。
- (void)viewWillDisappear:(BOOL)animated {
[self clearImageCacheFromMemory];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
[self clearImageCacheFromMemory];
// Dispose of any resources that can be recreated.
}
-(void)clearImageCacheFromMemory{
SDImageCache *imageCache = [SDImageCache sharedImageCache];
[imageCache clearMemory];
}