SDImageCache set maxMemoryCost 不执行任何操作.内存不断增加



我使用SDImageCache从表视图缓存图像,但是向下滚动时内存不断增加。所以我检查了库并在SDImageCache.h中找到了属性以设置maxMemoryCost,并期望缓存将被删除超过此限制。但在我的测试中,[SDImageCache sharedImageCache] 不会删除任何内容。所以这个属性目前什么都不做。

应用程序最终将在巨大的内存大小上崩溃。

谢谢

您好,我遇到了同样的问题,并在我的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

希望这对您有所帮助,让我知道

对我来说

,清除内存缓存可以解决问题。

- (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];
}

最新更新