maui icon indicating copy to clipboard operation
maui copied to clipboard

Massive memory leak in CollectionView while scrolling

Open Vroomer opened this issue 2 years ago • 2 comments

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

Vroomer avatar Oct 07 '22 22:10 Vroomer

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Oct 10 '22 12:10 ghost

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

HausBJB avatar Oct 29 '22 08:10 HausBJB

Any update on this?

wubalubadubdub55 avatar Dec 10 '22 23:12 wubalubadubdub55

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

mlancione avatar Dec 12 '22 14:12 mlancione

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

LennoxP90 avatar Dec 12 '22 17:12 LennoxP90

I've been testing memory leak issues with this app.

These should fix this:

  • https://github.com/dotnet/maui/pull/13260
  • https://github.com/dotnet/maui/pull/13333
  • https://github.com/dotnet/maui/pull/13327

(I marked the last one to close this when merged)

jonathanpeppers avatar Feb 16 '23 15:02 jonathanpeppers

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?

JanZeman avatar Feb 24 '23 07:02 JanZeman

@JanZeman your issue looks like this one: https://github.com/dotnet/maui/pull/13530

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

jonathanpeppers avatar Feb 24 '23 14:02 jonathanpeppers

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

JanZeman avatar Feb 25 '23 10:02 JanZeman