question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to properly clear cache?

See original GitHub issue

Hi @daniel-luberda

I need your help to understand how to clear cache in some specific cases? here is my scenario

I have mainpage with 3 horizontal listviews with each datetemplate has CacheImage as CacheType Memory implemented. when i profile after main page is loaded, I reach to 100mb memory usage although I am using Downsampling correctly I believe. If I remove lists I experience around 50mb. I can even accept 100mb for mainpage but my problem starts after I navigate to page 1 with a single listview with images it increases to 120 mb. How can I dispose or get rid off images loaded on Mainpage? I tried to set null ItemsSource each listview in OnDisappearing method of the mainpage but it didnt help at ll?

protected override void OnDisappearing()
     {
         base.OnDisappearing();

         // in order keep memory usage lower
         listview1.ItemsSource = null;
         listview2.ItemsSource = null;
         listview3.ItemsSource = null;
        
     }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
daniel-luberdacommented, Dec 14, 2017

FFImageLoading manages memory usage automatically, you shouldn’t worry about anything in most scenarios. If you exceed MaxMemoryCacheSize (configurable), it automatically removes bitmaps that are least used from memory, the rest is managed by OS. You shouldn’t worry about memory usage until loading some huge amounts of images or some big size images.

If you still want manually remove an entry from cache you can easily do that with:

await ImageService.Instance.InvalidateCacheEntryAsync("image.png or http://something", Cache.CacheType.Memory, removeSimilar: true);

But I advise you to not do that as it isn’t necessary.

1reaction
daniel-luberdacommented, Dec 20, 2017

if I use cachetype memory, does it make sense to use CacheDuration, once i exit the app, memory cache will be release I guess.

In that case this is ignored as no disk cache is involved.

I expect that page is disposed. but if there is cached image in the memory, page might be still in the memory and never disposed. Have you ever checked this with a profiler.

It’s not how it works. Bitmaps are not related to the Xamarin.Forms at all, they’re strictly native objects and OS manages them automatically. Page will be disposed without any issues, but the bitmap would be cached so it could be loaded faster for other image loading tasks. FFImageLoading uses LRU memory cache, so only most used bitmaps are cached, others are freed if memory usage is to high.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a cache? How to clear a cache & more
Click More Tools > Clear Browsing Data. A pop-up menu appears. To delete all data from the cache, select All time. Check the...
Read more >
How to Clear Cache for All Major Browsers
One way to have cache clearing happen in the background is by adjusting the field to Remove History Items. You'll pick a certain...
Read more >
How to Clear Your Browser Cache
Firefox clear cache · Click the menu button. and select Options. · Select the Privacy & Security panel. · In the Cookies and...
Read more >
Clear your web browser's cache, cookies, and history
If you need to clear your cache, cookies, and history for ... Select Safari > Quit Safari or press Command-Q to exit the...
Read more >
How Do I Clear My Browser Cache? - SDSU
INSTRUCTIONS ; Select the Google Chrome menu clear-cache-dots , which appears as three dots in the right corner of the browser window. Then ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found