Bug 43941 - Memory leak with ListView's RecycleElement on iOS
Summary: Memory leak with ListView's RecycleElement on iOS
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.2
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-09-01 14:56 UTC by Falko Schindler
Modified: 2017-07-05 06:19 UTC (History)
11 users (show)

Tags: ac iOS memory
Is this bug a regression?: ---
Last known good build:

Simple test case (24.47 KB, application/zip)
2016-09-22 04:59 UTC, Falko Schindler

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Falko Schindler 2016-09-01 14:56:51 UTC
The following example app allows you to open a ListPage containing a ListView with the RecycleElement strategy. When opening this page repeatedly by pressing the "Push" button, we should see "Constructor" and "Destructor" printed on the command line. (The garbage collector is triggered right within the constructor.) But on iOS the destructor is never called when using the RecycleElement strategy.

The MainPage contains nothing but a button:

    MainPage = new NavigationPage(new ContentPage {
        Content = new Button {
            Text = "Push",
            Command = new Command(o => MainPage.Navigation.PushAsync(new ListPage())),

The ListPage contains only a ListView and logs the construction and destruction to the command line:

    public class ListPage : ContentPage
        public ListPage()

            Title = nameof(ListPage);
            Content = new ListView(ListViewCachingStrategy.RecycleElement) { // NOTE: no destruction with RecycleElement strategy!
                ItemsSource = new List<string> { "A", "B", "C" },


I wasn't able to find a workaround except for switching the caching strategy to RetainElement.
Comment 1 Cliff Cawley 2016-09-08 22:59:43 UTC
I just found this exact same problem so I can confirm it happens for me as well. If I switch to RetainElement then the destructor is correctly called
Comment 2 Jeffrey Romine 2016-09-20 12:59:02 UTC
I have the same problem and noticed that the memory leaks when switching the content of MainPage.  If I set the Listviews to RetainElement the memory leak goes away.
Comment 3 Jeffrey Romine 2016-09-20 13:05:58 UTC
I can confirm this is not limited to iOS.  It also is leaking memory on Android as well.
Comment 4 Ashley Gazich [MSFT] 2016-09-21 21:57:12 UTC
Hi, thank you for filing this report! Could you please attach a minimized runnable test case exhibiting the memory leak for investigation?
Comment 5 Jeffrey Romine 2016-09-21 21:59:21 UTC

This is an example of it happening when switching the MainPage from one page to another.
Comment 6 Falko Schindler 2016-09-22 04:59:40 UTC
Created attachment 17664 [details]
Simple test case
Comment 8 Rui Marinho 2016-10-04 11:30:25 UTC
Can see the issue still in 2.3.3
Comment 9 adrianknight89 2016-11-12 07:39:10 UTC
I'm able to reproduce this on iOS in RetainElement mode as well. The issue also exists when the list is empty.
Comment 10 adrianknight89 2016-11-12 19:46:05 UTC
See https://github.com/xamarin/Xamarin.Forms/pull/524
Comment 11 Rui Marinho 2017-01-26 14:30:33 UTC
Should be fixed in 2.3.5-pre1
Comment 12 Saurabh Paunikar 2017-07-05 06:19:05 UTC
Verified using Xamarin.form version =

ScreenCast link: https://www.screencast.com/t/cVy9vIoj