Skip to content

Massive memory leak in CollectionView while scrollingΒ #10560

Closed

Description

@Vroomer

Description

Scrolling through items in CollectionView leads to massive memory leak if the DataTemplate has Grid/VerticalStackLayout/HorizontalStackLayout as its first children. Wrapping the layout inside a Border solves the issue.

DataTemplate causing the issue:

            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <HorizontalStackLayout>
                        <Label Text="{Binding .}" />
                    </HorizontalStackLayout>
                </DataTemplate>
            </CollectionView.ItemTemplate>

DataTemplate solving the issue:

            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Border>
                        <HorizontalStackLayout>
                            <Label Text="{Binding .}" />
                        </HorizontalStackLayout>
                    </Border>
                </DataTemplate>
            </CollectionView.ItemTemplate>
  • Speed of scrolling doesn't seem to affect the issue.
  • GC is getting triggered, but the memory keeps going up infinitely in spite.
  • The memory leak is really significant and makes the app unusable very quickly.
  • Attached repository is 7.0.0-rc.1.6683, but I had the same problem in 6.0.x.
  • Android was tested only on Windows Subsystem for Android and the problem seems to be the same.

Steps to Reproduce

  1. Load the repository and run the example.
  2. Scroll up and down in the CollectionView.
  3. Watch the memory usage in ResMon/memory profiler.

Link to public reproduction project repository

https://github.com/Vroomer/MAUI-CollectionView-memory-leak.git

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Windows SDK 10.0.22000, Windows subsystem for Android 2207.40000.8.0

Did you find any workaround?

Wrapping DataTemplate's layout children inside Border solves the issue.

Relevant log output

No response

Activity

  1. added
    t/bug
    on Oct 7, 2022
  2. added
    legacy-area-perf
    area-controls-collectionview
    on Oct 10, 2022
  3. self-assigned this
    on Oct 10, 2022
  4. added this to the Backlog milestone on Oct 10, 2022
  5. HausBJB commented on Oct 29, 2022

    @HausBJB

    Hello, is there any news? These are things that should be in as soon as possible. Every app has lists and how can you expect to publish an app with such a performance.

    Thanks

  6. Majestic-Mustang commented on Dec 10, 2022

    @Majestic-Mustang

    Any update on this?

  7. mlancione commented on Dec 12, 2022

    @mlancione

    Any update from MS on this? Seems like a serious issue with a basic control.

  8. LennoxP90 commented on Dec 12, 2022

    @LennoxP90

    wrapping in border didn't solve my issue (performance)
    I noticed you are not using compiled bindings either which I am

  9. added
    p/1
    on Dec 17, 2022
  10. 7 remaining items

  11. added
    fixed-in-8.0.0-preview.1.7762
    on Feb 23, 2023
  12. JanZeman commented on Feb 24, 2023

    @JanZeman

    Hello @jonathanpeppers, thank you very much for your recent memory leaks fixes! It is very encouraging to see someone tries to attack those (seems to be mid-, long-term) problems. I observed memory leaks in CollectionView / ObservableCollection scenario not only during the scrolling but also when modifying the ObservableCollection content or assigning a new ObservableCollection to the existing CollectionView. Being MAUI hobbyist I was not sure I did everything perfectly so I tried to analyze some MAUI tutorials I found on YouTube and I was able to reproduce there as well. This is one of them: Memory leak on every search executed which is a fork of this one. Do I understand correctly that your recent changes might have fixed this kind of memory leaks as well?

  13. jonathanpeppers commented on Feb 24, 2023

    @jonathanpeppers
    Member

    @JanZeman your issue looks like this one: #13530

    I want to investigate a bit more to understand why it only happens on Windows, but we should get this one in soon.

  14. JanZeman commented on Feb 25, 2023

    @JanZeman

    @jonathanpeppers Yes, that looks way closer to mine issue. Out of curiosity I will try to understand more there. Thank you!

  15. ghost locked as resolved and limited conversation to collaborators on Mar 27, 2023
  16. added
    perf/general
    and removed
    legacy-area-perf
    on May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-controls-collectionviewfixed-in-8.0.0-preview.1.7762p/1perf/generalplatform/androidplatform/windowst/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions