This repository was archived by the owner on May 1, 2024. It is now read-only.
  
  
  
  
  
Description
Description
ViewCell's with nested layout (for example StackLayout with a ContentView) cause the whole ListView to be never destructed. The garbage collector seems unable to remove the ListView and it's ViewCells even though they are not referenced anymore.
Steps to Reproduce
Build and run this code:
public class App : Application
{
    public App()
    {
        MainPage = new NavigationPage(new ContentPage
        {
            Content = new Button
            {
                Text = "Show New ListView",
                Command = new Command(o => MainPage.Navigation.PushAsync(new ListPage())),
            },
        });
    }
}
public class ListPage : ContentPage
{
    public ListPage()
    {
        GC.Collect();
        Content = new ListView
        {
            ItemTemplate = new DataTemplate(typeof(Cell)),
            ItemsSource = new List<string> { "A" },
        };
    }
}
class Cell : ViewCell
{
    string guid = Guid.NewGuid().ToString();
    public Cell()
    {
        Console.WriteLine("Constructor " + guid);
        View = new StackLayout
        {
            Children = {
                new ContentView
                {
                    Content = new Label { Text = guid },
                }
            }
        };
    }
    ~Cell()
    {
        Console.WriteLine("Destructor " + guid);
    }
}
 
Open and close the page with the ListView a few times.
Expected Behavior
Destructor should be called.
Actual Behavior
ListPage, ListView and the Cells are never removed by the garbage collector causing huge memory leak.
Basic Information
- Version with issue: Xamarin.Forms 2.5 and 3.0-pre3
 
- Last known good version: none
 
- IDE: Visual Studio for Mack
 
- Platform Target Frameworks: