Memory Leak In Xamarin Forms CachedImage When Using Grid
See original GitHub issueHere is the scenario I followed:
Get an image from Android photo gallery as a byte array (possibly a downsampled size of 3MP). Create a CachedImage with DownsampleWidth = 100 and DownsampleUseDipUnits = true. Set the source of the CachedImage as photo.Source = ImageSource.FromStream(() => new MemoryStream(photoByteArray)). Then add this to a List<CachedImage> photoViews
list.
After each addition or removal, update the Grid with the following code:
public void ArrangePhotoViews()
{
photosGrid.Children.Clear();
int row = 0;
int column = 0;
for (int i = 0; i < photoViews.Count; i++)
{
photosGrid.Children.Add(photoViews[i], column, row);
if(column == 0)
{
column = 1;
}
else if(column == 1)
{
column = 0;
row++;
}
}
}
I used Android Studio to track memory usage. Every time ArrangePhotoViews
is called, regradless whether it is an addition or a removal operation, memory increases as if every photo in the list is newly being created and added to the grid.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Memory Leak In Xamarin Forms CachedImage · Issue #782
I used Android Studio to track memory usage. App starts with 11.66 MB and ends with 14.66 MB. Removing the images has no...
Read more >Cached image (ffimageloading) with OUT OF MEMORY ...
update: I have Searched so much...Do I need a cache key?? listview · exception · xamarin · xamarin.forms · xamarin.android.
Read more >How to Prevent Memory Leak and Profiling in Xamarin ...
In this article, you will learn how to prevent memory leak and profiling in Xamarin applications.
Read more >Recent Threads - Xamarin Community Forums - RSSing.com
ListView memory leaks ... I have a Xamarin Forms application. On the main page there is a ListView, every view cell contains text...
Read more >Your Xamarin application is probably leaking memory and ...
Your Xamarin application is probably leaking memory and you don't know it. One of the least used Xamarin tools, the Profiler, should actually ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was mistaken to think that Android Monitor’s Garbage Collect button would also trigger a garbage collection on Xamarin (.Net) side. After using GC.Collect() from code, I saw that there was no leak.
@EmilAlipiev I manually forced garbage collection just to test the memory usage, that was not meant for managing caching. As far as I understand, what you are trying to do is to clear the cache. @daniel-luberda has recommended me to use the ImageService.Instance.InvalidateMemoryCache() method of the library for that purpose in another thread(see https://github.com/luberda-molinet/FFImageLoading/issues/782). But I would not want to misguide you as I am not an expert on the library. You can find the documentation here: https://github.com/luberda-molinet/FFImageLoading/wiki