Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak when scrolling a CollectionView with IsGrouped=true #17698

Open
tranb3r opened this issue Sep 27, 2023 · 9 comments
Open

Memory leak when scrolling a CollectionView with IsGrouped=true #17698

tranb3r opened this issue Sep 27, 2023 · 9 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView memory-leak 💦 Memory usage grows / objects live forever migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.)
Milestone

Comments

@tranb3r
Copy link

tranb3r commented Sep 27, 2023

Description

On android with net8-rc.1, I'm comparing the memory usage of a CollectionView with or without IsGrouped.
When scrolling a CollectionView with IsGrouped=true, the memory usage increases infinitely.
When scrolling a CollectionView with IsGrouped=false, the memory usage is stable.

Steps to Reproduce

  1. Open repro project
  2. On the first tab, tap on Add button, it will create a CollectionView with IsGrouped=false.
  3. Scroll the CollectionView up and down. Observe memory usage with dotnet-gcdump. It is stable.
  4. On the second tab, tap on Add button, it will create a CollectionView with IsGrouped=true.
  5. Scroll the CollectionView up and down. Observe memory usage with dotnet-gcdump. It is slowly increasing.
  6. Alternatively, open the attached gcdump files I've captured when scrolling the second tab. Between the first (memory-12.gcdump) and second (memory-19.gcdump), the size diff is +144,688 for object type List<Microsoft.Maui.Controls.Element>.

gcdump.zip

Screenshot 2023-09-27 173020

Link to public reproduction project repository

https://github.com/tranb3r/Issues/tree/main/MauiAppCollectionViewGroupingLeak

Version with bug

8.0.0-rc.1.9171

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 34

Did you find any workaround?

No workaround

Relevant log output

No response

@tranb3r tranb3r added the t/bug Something isn't working label Sep 27, 2023
@jsuarezruiz jsuarezruiz added legacy-area-perf Startup / Runtime performance area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Sep 28, 2023
@mattleibow mattleibow added the memory-leak 💦 Memory usage grows / objects live forever label Oct 24, 2023
@mattleibow mattleibow added this to the Backlog milestone Oct 27, 2023
@ghost
Copy link

ghost commented Oct 27, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@tranb3r
Copy link
Author

tranb3r commented Oct 28, 2023

@jonathanpeppers @samhouts
I know you're busy with net8 GA preparations.
But I was hopping this issue could be investigated.
How can I help?

@mjsb212
Copy link

mjsb212 commented Nov 13, 2023

Profiling on 8.0.100-rc.2 shows same result in GC Dump

@jonathanpeppers
Copy link
Member

Looking at @tranb3r's two dumps, I came to a similar conclusion that a List<Element> appears to just be growing and growing.

Let me investigate some more; thanks for filing this!

jonathanpeppers added a commit to jonathanpeppers/maui that referenced this issue Nov 17, 2023
@jonathanpeppers
Copy link
Member

My thoughts here, is the problem might be related to what I saw here:

So, I tried something like this: main...jonathanpeppers:IsGroupedCollectionView

But the test passes, and I also don't think it fixes the sample app above.

I am going to be on vacation for a bit, so just writing this down for anyone else -- (or myself when I return 😄).

@tranb3r
Copy link
Author

tranb3r commented Dec 12, 2023

Any progress?

@mjsb212
Copy link

mjsb212 commented Dec 14, 2023

Also likely related to #18881 -- When I remove IsGrouped the scrolling is smooth with the GridItemsLayout & images. Anyone figure out why yet?

@jonathanpeppers
Copy link
Member

@mjsb212 this one is specificly about CollectionView on Android. So if you are seeing an issue on another platform, file a new issue, thanks!

I'm putting this on the list of "scrolling performance" issues we're ramping up to work on in the next few months.

@mjsb212
Copy link

mjsb212 commented Dec 27, 2023

@tranb3r @jonathanpeppers -- Just to clarify: I am on Android and Release Build and after testing and profiling with dotnet trace & GC Dump, the issue I reported at #18881 seems to be related to this memory leak -- List<Element> appears to just be growing and growing when I have IsGrouped=true & that's why my large collection of images starts to lag as I scroll down & reach the end of the list. If I remove the grouping then all is fine, and scroll works well with the same exact size collection. Hope this one is addressed soon. After alot of profiling and testing I see .net 8.0 CollView has 100X better performance with most use cases, so thanks for all the work put in to address the performance issues -- looking forward to the 9.0. improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView memory-leak 💦 Memory usage grows / objects live forever migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.)
Projects
None yet
Development

No branches or pull requests

8 participants