Bug 45905 - ListView ItemSource change slower with every refresh
Summary: ListView ItemSource change slower with every refresh
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-10-26 06:52 UTC by Philipp Sumi
Modified: 2017-03-16 18:26 UTC (History)
3 users (show)

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 Philipp Sumi 2016-10-26 06:52:42 UTC
Issue originally posted at:


Short version:

ListView is getting slower and slower with every refresh, probably due to a rendering/templating leak.
Solution is to set the CachingStrategyof my ListView to RecycleElement.

Long version:

I'm encountering a rather concerning issue with a Vanilla ListView. When issuing a refresh command, I'm replacing the ListView's data source completely. This is fast in the beginning and then gets slower every time with the refresh indicator freezing. Even though I'm currently only returning five items, the refresh hangs towards a minute on the 5th repetition and then hangs basically forever or crashes the app.

Below is my code. Note that invoking the last two lines on the UI thread also didn't fix the problem:

            List<Items> items= await rideService.FindRides(Ride.Id);
            Items = items;
            OnPropertyChanged(() => Items);

The problem seems to be with ItemTemplate- it contains a grid, a few bindings and converters. Nothing too serious. If I replace it with an empty template, the performance is ok. But still - it's just 5 items, which means a max of 30 templates in memory after 5 refreshes... There seems to be some seriously leaky behavior here.

Now: I could get around this by explicitly setting the CachingStrategyof my ListView to RecycleElement. This seems to further indicate that the hangs are produced by a leaky template rendering mechanism.
Comment 1 adrianknight89 2016-11-14 07:01:15 UTC
Which platform are you seeing this on? Also, if you could attach a repro, it's better.
Comment 2 Philipp Sumi 2016-12-01 19:01:34 UTC
Platform is Xamarin Forms. I don't have a repro right now, may be able to create one in the foreseeable future. Especially because the RecycleElement is buggy too: While it doesn't crash the app, Labels in recycled templates get truncated if they are being assigned longer strings.


Label with text "Ava", rendered

Then scrolling down, and a user called "Alexandra" gets rendered as "A.." even though there's plenty of space for the label.
Comment 3 Philipp Sumi 2016-12-05 09:51:26 UTC
Another observation: I have another listview, again with a bigger data template, and 4 items. Three of them are visible. I noticed that if I scroll just up and down, scrolling gets slower and slower until the up becomes unresponsive, if I don't set the CachingStrategy to "RecycleElement". So it appears it's not a memory leak as I assumed (because the refreshing used to kill the app), but smth else.
Comment 4 Samantha Houts [MSFT] 2016-12-05 19:10:29 UTC
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue, we would very much appreciate it.  
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d  
Warm regards, 
Xamarin Forms Team
Comment 5 Philipp Sumi 2017-03-16 11:54:28 UTC
Hi Samantha

I removed all ListView usages from my app and replaced them with a custom control that got rid of all the issues I had (which were tons). Sorry I can't help more...
Comment 6 Samantha Houts [MSFT] 2017-03-16 18:26:12 UTC
@Philipp Sumi: Thank you for letting us know! I will close this report for now until we can get further information about it, since we can't know for sure if we've resolved it without a definitive test case to work against. Please feel free to reopen it later or submit another report if you encounter any further issues. Thank you again for your report!