Hello,
i got memory leak on android when using
alexrainman's CarouselView with FFImageLoading.
I got like 100 or more images. After swiping thru Cached Image i got OOM.
My control:
ImageService.Instance.Initialize(new Configuration
{
MaxMemoryCacheSize = 52428800
});
stack trace:
https://pastebin.com/qvQbMdHD
Am I doing something wrong? Shouldn't it just free memory after disappearing?
One more thing DownsampleToViewSize won't work correctly if you don't have fixed image sizes. I would recommend using DownsampleWidth/DownsampleHeight instead. It's mentioned in the WIKI.
Yeah wouldn't trust Xamarin's current CarouselView to not leak memory. It causes leaks for us while using FF. I bet if you convert that to a list view you will stop seeing the leak, that would prove to you that it is not FF but the CarouselView. Thankfully there is going to be a stable version of CarouselView in the near future.
I made some changes to make it as simple as possible and ended up with:
<ListView ItemsSource="{Binding Items}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" CachingStrategy="RecycleElement" Grid.Row="1">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ffimageloading:CachedImage Source="{Binding Url}" Aspect="AspectFit" VerticalOptions="Center" HorizontalOptions="Center" DownsampleUseDipUnits="True" LoadingPlaceholder="loading.png" ErrorPlaceholder="image_error.png" CacheDuration="{Binding CacheDuration}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Its allocating like 200+mb for my app and then it stop loading new images(on listview rescrolling after few sec "fixes it"). e.g. i got about 50 pictures, (jpg about each 200kb) and it stops loading after about 25, then loads new when scrolled down to like 35)
tried v2.2.9 and v2.2.10 and even 2.1.8 of Xamarin.FFImageLoading.Forms
Tested on Samsung S4 mini and Xperia S
Checked with and without MaxMemoryCacheSize.
I can add, that i got custom HttpClient(for authorization purposes).
another stack trace(with crash on v2.2.9 with ListView):
https://pastebin.com/iW72VSNQ
You didn't enable downsampling, please set DownsampleWidth or DownsampleHeight property too. Could you paste some code for your custom http client? There are many ListView examples in our sample project (which is also Xamarin.Forms app) and there are no leaks there.
My HttpClient uses custom HttpClientHandler which just override base.SendAsyc to add token to header. And I found 2 problems.
As I said earlier, the Exception might be misleading. FFImageLoading just informs you that the OOM occured and no more images can be loaded (as application would crash). The reason of memory leaks can be a lot of other things though. You should probably report a bug on CarouselView project page.
It has been reported but Xamarin gave up on that code. They are merging a community project as the new carousel view (https://github.com/xamarin/Xamarin.Forms/pull/853). I haven't tried that project but seems promising.
I'll close this then as it should be handled on the on the CarouselView's / Xamarin.Forms side. Feel free to reopen if you'll have some new informations. Thanks.
Anyway here is a repro for this issue:
https://github.com/7lol/MemoryLeak
Can you tell me if clearing memory like:
FFImageLoading.ImageService.Instance.InvalidateMemoryCache();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
should be enough?
Anyway if ill open Listview 2-3 times, and scroll down it crashes.