Forum Xamarin.Forms

ListView memory leaks

I have a Xamarin Forms application. On the main page there is a ListView, every view cell contains text with image. When I start to scroll from beginning to end, after that from the end to the beginning and again and again, the app crashes. Any scrolling increases the allocated memory and after several steps the app crashes.

                ItemsSource="{Binding ViewData}"
                                <ffimageloading:CachedImage  Grid.Row="0" DownsampleToViewSize="True" Aspect="AspectFill"       x:Name="MainPhoto">
                                        <TapGestureRecognizer Tapped="MainPhotoTapped" NumberOfTapsRequired="1"/>
                                <Label Text="Click here"></Label>

The image's source is set in the code behind in the Viewcell's BindingContextChenged method. Is there some resolution for this problem?

Best Answer


  • Yes, I have tried to set the CachingStrategy to RecycleElement, but the behaviour is the same.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Can you add a repo?
  • I m using ByteArrayToImageConverter to convert byte array i m getting from SQL server databse , the converter as below

     public class ByteArrayToImageConverter : IValueConverter
            public ImageSource retSource;
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
               // ImageSource retSource = null;
                if (value != null)
                    byte[] imageAsBytes = (byte[])value;
                    // byte[] decodedByteArray = System.Convert.FromBase64String(Encoding.UTF8.GetString(imageAsBytes, 0, imageAsBytes.Length));
                    // var stream = new MemoryStream(decodedByteArray);
                    retSource = ImageSource.FromStream(() => new MemoryStream(imageAsBytes));
                return retSource;
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
                //return null;
                throw new NotImplementedException();

    my problem when i show all the images in the xaml list view ( bind with my model) i m having memeory leaks , every time i open the list view the memory is growing gradually , Whast is the solution to reduce the memeor leaking issue with the converter and list view ( by the way i m using CachingStrategy="RecycleElement" but it dosent reduce the memory leak. please if anyone across this type of issue please let me know.

    with full descriptions in stackoverflow as below

    Thank you inadvance for your support.

  • jariwalahetaljariwalahetal USMember ✭✭

    Did you found any solution for this?

Sign In or Register to comment.