Skip to content

memory cache always fail after recieving memory warning over 2 times? #1594

@mingyue1991

Description

@mingyue1991

Issue Info

Info Value

Platform Name ios
Platform Version 9.3 ,8.4,(maybe ocurr in any version)
SDWebImage Version 3.7.5
Integration Method cocoapods
Xcode Version Xcode 7.3.1
Repro rate 90%
Repro with our demo prj it happen with demo project

Issue Description and Steps

in my application,we have feeds with many images. sometimes we find all the imagesviews flicker when we reloadData all just setImage,each time it happen, all imageViews from any page will flicker.then i looked into the SDWebImage code and got the way to reappear it. in the Demo, we can reapear it to,just
change this method to:

    - (void)flushCache
{
    [self.tableView reloadData];
//    [SDWebImageManager.sharedManager.imageCache clearMemory];
//    [SDWebImageManager.sharedManager.imageCache clearDisk];
}

then ,we loaded in the simulator and the images all downloaded and showed, then we choose simulator's hadware to simulate Memory warning.then we reloadData(after change above method ,we can just click clear cache button), at this time the images flicker but it's ok,it's logical because the SDImageCache will clear the memory (by calling [self.memcache removeAllObject]), and must load imageData from disk.then we reloadload data a few times, it won't flicker ,because SD will save it to memCache(by[self.memCache setObject:diskImage forKey:key cost:cost];) after load from disk. It seems all right, no problem.

But if we repeat above Steps (continue simulate Memory Warning more than once),we find it always flicker when we reloadData,and i find the reason is that the image will alway be nil when
UIImage *image = [self imageFromMemoryCacheForKey:key]; which means we can't get cache from memory forever, even if it actually called [self.memCache setObject:diskImage forKey:key cost:cost].
it's confused, when it call setObject ,this delegate called - (void)cache:(NSCache *)cache willEvictObject:(id)obj; then the object will Evict.
is it the NSCahce's logic or issue?somebody say after called removeAllObject, then NSCache can't setObject , but I didn't find any document suggest it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions