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 (show other bugs)
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)

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


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

Note You need to log in before you can comment on or make changes to this bug.