Alex9494
Alex9494

Reputation: 1778

IOS remove cache when leaving controller - kingfisher

I use kingfisher to load pictures from urls in a tableview. In my controller I have a tableview to display the pictures, a "next" button to reload tableview with new pictures, and a "home" button to go from this view controller to the home view controller.

I use this kind of code to load pictures:

cell.imageInTableCell?.kf.setImage(with: url)

And this to clear my cache when I click on the next button to update the pictures:

ImageCache.default.removeImage(forKey: photoUrl1)

It works fine, I can see ups and downs in my memory use.

My issue is when I try to clear cache when I click on the home button. I used code such as:

ImageCache.default.removeImage(forKey: photoUrl1)

Or:

let cache = KingfisherManager.shared.cache
        cache.clearMemoryCache()
        cache.clearDiskCache()
        cache.cleanExpiredDiskCache()

Or:

ImageCache.default.clearMemoryCache()
ImageCache.default.clearDiskCache()
ImageCache.default.cleanExpiredDiskCache()

It doesn't work, I don't see my memory use decrease. I put these codes in an IBAction with a touchUpInside event, in prepareForSegue and in didReceiveMemoryWarning but nothing happens.

Here is my memory usage when i only use the next button: enter image description here

And here is my issue with the home button then reload my controller with the pictures then hit the home button again etc : enter image description here

Do you see what is wrong?

Thank you,

Upvotes: 2

Views: 3650

Answers (2)

tBug
tBug

Reputation: 827

If you want to release a lot from memory, ( only what kingfisher has cashed )

ImageCache.default.memoryStorage.removeAll()

Upvotes: 1

Mohamed Helmy
Mohamed Helmy

Reputation: 832

the cashed image not cash in memory it cashing in physical place in disk so you will not detect any changing of memory if clear Memory cache, don't worry it's woking fine.

if you want it to be cashed in memory only you have to use this.

/// If set, Kingfisher will only cache the value in memory but not in disk.

case cacheMemoryOnly

See this link https://github.com/onevcat/Kingfisher/blob/master/Sources/KingfisherOptionsInfo.swift

Upvotes: 0

Related Questions