2

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,

Alex9494
  • 1,588
  • 3
  • 12
  • 22
  • You should not clear the caches yourself. Kingfisher handles memory automatically if you set a maximum RAM usage. Example: `ImageCache.default.maxMemoryCost = 100` – Eric Aya Jun 25 '17 at 09:17

2 Answers2

1

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

ImageCache.default.memoryStorage.removeAll()
tBug
  • 789
  • 9
  • 13
0

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

Mohamed Helmy
  • 821
  • 1
  • 9
  • 20
  • I want the same behaviour when I click on the "next" and "home" buttons. For now I see ups and downs in memory with the next button, but only ups with the home button. – Alex9494 Jun 24 '17 at 23:34
  • the code is right but i think you have to check instruments to see the memory leak – Mohamed Helmy Jun 24 '17 at 23:39
  • I tried different things, the current code is : @IBAction func homeButtonTap(_ sender: Any) { ImageCache.default.clearMemoryCache() ImageCache.default.clearDiskCache() ImageCache.default.cleanExpiredDiskCache() } and I have a segue from the home button to home view controller in storyboard – Alex9494 Jun 25 '17 at 00:01
  • Thank you foro your help, my main issue came from a retain cycle caused by firebase observers not removed. – Alex9494 Jun 26 '17 at 11:21