Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] ListView with HasUnevenRows="True" is leaking memory (items) #10820

Closed
alexeystrakh opened this issue May 22, 2020 · 4 comments · Fixed by #12447
Closed

[Bug] ListView with HasUnevenRows="True" is leaking memory (items) #10820

alexeystrakh opened this issue May 22, 2020 · 4 comments · Fixed by #12447
Labels
a/listview Problems with the ListView/TableView a/performance e/5 🕔 5 in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 partner/cat 😻 t/bug 🐛

Comments

@alexeystrakh
Copy link

alexeystrakh commented May 22, 2020

Description

ListView with HasUnevenRows="True" somehow retains items bound to the list view in memory even after full data reload. Basically every reload dumps old entries and creates new items, but old items don’t go away. I was troubleshooting it, trying to find, what exactly retains the entries and found one particular line which caused that: HasUnevenRows="True". Having that information I recreated a sample solution and was able to reproduce the issue by adding that line to my simple ListView with a simple data binding to an ObservableCollection. The number of retained items in memory depends on the Grouping flag, if enabled then all items are retained, if disabled, only 1 per each refresh cycle is retained in memory.

Additional tests

  1. CollectionView in a similar scenario does not leak memory (ItemSizingStrategy= MeasureAllItems)
  2. If a page which holds the listview is closed, then the list view and all items deallocated as well (even leaked)
  3. Grouping is not the primary cause of the leak but with that enabled all the items are leaking
  4. This memory leak affects iOS only, and no memory leak is happening on Android.

Steps to Reproduce

  1. Launch the sample app with Xamarin Profiler attached (allocations mode)
  2. The page will be automatically dumping all bound data and reloading new (10 cycles)
  3. In Xamarin Profiler filter to MyTestItem class, mark only live objects and observe that no all of them are garbage collected

Expected Behavior

Only items currently bound to the listview stay in memory

Actual Behavior

Some of the items are retained in memory. If you enabled grouping then ALL items will be retained.

Basic Information

  • Version with issue: 4.6.0.800
  • Last known good version: N/A
  • IDE: VS4Mac 8.6.4526
  • Platform Target Frameworks: iOS (only)
    • iOS: 13.18.1.31
  • Nuget Packages: None
  • Affected Devices: All

Screenshots

xf listview memoryleak 1

xf listview memoryleak

Reproduction Link

The sample project is here (master branch):
https://github.com/alexeystrakh/xamarinforms-listview-memoryleak

There are a few additional tests with grouping enabled in a separate branch:
https://github.com/alexeystrakh/xamarinforms-listview-memoryleak/tree/master-leak-with-grouping

And navigation which frees the ListView:
https://github.com/alexeystrakh/xamarinforms-listview-memoryleak/tree/master-leak-with-navigation

Workaround

If the page which holds the listview is a root page, there is no workaround, but if the page is a details page, closing that page will let the listview go, which in turn lets all the retained items go.

@alexeystrakh alexeystrakh added s/unverified New report that has yet to be verified t/bug 🐛 labels May 22, 2020
@jsuarezruiz jsuarezruiz added a/listview Problems with the ListView/TableView a/performance p/iOS 🍎 labels May 25, 2020
@samhouts samhouts added e/5 🕔 5 partner/cat 😻 and removed s/unverified New report that has yet to be verified labels May 26, 2020
@samhouts samhouts added this to the 5.0.0 milestone Aug 5, 2020
@t-johnson
Copy link
Contributor

Same issue reported as in #6742 ?

@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
@samhouts samhouts added the in-progress This issue has an associated pull request that may resolve it! label Nov 2, 2020
@AlanYost
Copy link

AlanYost commented Feb 3, 2021

@t-johnson - Is there a way we can expedite the approval of your fix? The ListView control with variable heights is so critical to us, but your PR has been outstanding for a few months now...

@t-johnson
Copy link
Contributor

@AlanYost - sorry, I'm just providing a contribution. If the xamarin team don't feel its the most valuable use of their time to deal with my PRs, theres not a lot I can do.
In this case, I believe ListView is a deprecated control, in favor of CollectionView, so I can understand why this might take a lower priority to other things they're dealing with (eg, MAUI).

@AlanYost
Copy link

AlanYost commented Feb 3, 2021

Thanks for the reply Tim - CollectionView is a joke - It leaks immediately you just have to bind to a collection. We will try to push this through somehow :-) Actually just tested the CollectionView with latest 5.0.0 build and it looks better - one minor leak but much more stable!

rmarinho pushed a commit that referenced this issue Jul 6, 2021
fixes #6742 fixes #10820

* Fixes #6742
The Item created to measure was never removed, causing memory leak until the page is closed.

* cleanup

* cleanup, remove UITEST code

* remove commented code

* remove unused variable

* Fix bad merge of project file.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/listview Problems with the ListView/TableView a/performance e/5 🕔 5 in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 partner/cat 😻 t/bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants