Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Memory leak in Xamarin Forms ListView with Custom Cells

$
0
0

I've been doing some research on a memory leak our enterprise app has. Thsi app is developed with Xamarin Forms.
After several tests i've found that ListViews with custom cell causes memory leak. I've done a simple XForms app, with most of the code taken from samples in the Xamarin documentation.

Xamarin.Forms Version 1.5.0.6446

A simple Person class:

public class Person
{
    public Person(string name, DateTime birthday, Color favoriteColor)
    {
        this.Name = name;
        this.Birthday = birthday;
        this.FavoriteColor = favoriteColor;
    }

    public override string ToString()
    {
        return Name;
    }

    public string Name { private set; get; }

    public DateTime Birthday { private set; get; }

    public Color FavoriteColor { private set; get; }

    public string ProfileImage { get { return "profile.png"; } }
}

Binded to this ListView

  <ListView x:Name="lstPeople"
            ItemsSource="{Binding People}"
            RowHeight="{StaticResource rowHeight}">
    <ListView.ItemTemplate>
      <DataTemplate>
        <local:BaseViewCell>
          <StackLayout BackgroundColor="#abc"
             Orientation="Vertical">
            <StackLayout Orientation="Horizontal">
              <Label Text="{Binding Name}"
              TextColor="#f35e20" />
              <Label Text="{Binding Name}"
              HorizontalOptions="EndAndExpand"
              TextColor="#503026" />
            </StackLayout>
          </StackLayout>
        </local:BaseViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>

In this simple implementation, i was able to reproduce a memory leak on Windows Phone (Device Lumia 1320). I tested this app with Windows Phone developer power tools 8.1 and with the built-in Windows Phone Application Analysis found in VS2013 and both tools give the same panorama. If i keep scrolling over the 150 persons the list has, memory continues increasing.

By now, our team decided to make a Custom list render for our application in order to get rid of this issue. But with this post i just want to publish all the research i've done for other developers that might encounter this issue. I would be glad if anyone at xamarin could give a read to this and address this Memory Leak.


Viewing all articles
Browse latest Browse all 77050

Trending Articles