Bug 54146 - List view memory leak when using Recycle Element Caching Strategy
Summary: List view memory leak when using Recycle Element Caching Strategy
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.4
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
Depends on:
Reported: 2017-03-28 18:25 UTC by Emman Vazz
Modified: 2017-03-28 21:42 UTC (History)
2 users (show)

Tags: ios, listview, memory leak
Is this bug a regression?: ---
Last known good build:

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 Emman Vazz 2017-03-28 18:25:47 UTC
I have tested with with the -pre6 and -pre2. If you take a look at my modified version of the Xamarin Forms Monkeys app https://github.com/EmmanVazz/Xamarin.Forms-Monkeys you will see that there is clearly a leak. You can push and pop the MonkeysPage and see the memory increase with each push.
Comment 1 Jimmy [MSFT] 2017-03-28 21:42:10 UTC
I ran the linked GitHub project on an iPhone 6 10.2 simulator and used the Profiler to monitor the allocations. I would push the ListView page, pop it, and then take a snapshot so I could compare the number of new allocations. 

I was able to reproduce the memory leak with Forms 2.3.4-pre6, however Forms showed a large improvement most likely due to this fix[1]. That fix is _not_ included in any of the 2.3.4 pre-releases.

# Test Results

## Forms 2.3.4-pre6
Pushing then popping the page would average 5,000 new allocations. This caused the total memory allocated to go from 1.9MB at launch to 2.4MB after the first push. It then increased about 0.2MB for each subsequent cycle resulting in a total memory allocation of 3.9MB at the end of the test. Looking at the debug output, the ListView page was _not_ being destroyed.

## Forms
Each cycle now only resulted in around 130 new allocations. The total memory went from 1.8MB at launch to 2.4MB after the first push again but it then stabilized even after subsequent cycles. The debug output also now indicated that the ListView page was being destroyed after it was popped.

Debug outputs: https://gist.github.com/jimmgarrido/1b6f190ca53756d2a815452445e03d58
Full Xamarin Profiler results: https://www.dropbox.com/sh/wgmsjgvt4qdgr5f/AAATrsWCsn_MDPW1fVduCJLoa?dl=0

[1] https://github.com/xamarin/Xamarin.Forms/pull/524