maui
maui copied to clipboard
Massive memory leak in CollectionView while scrolling
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
- Load the repository and run the example.
- Scroll up and down in the CollectionView.
- 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
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.
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
Any update on this?
Any update from MS on this? Seems like a serious issue with a basic control.
wrapping in border didn't solve my issue (performance) I noticed you are not using compiled bindings either which I am
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)
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 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 Yes, that looks way closer to mine issue. Out of curiosity I will try to understand more there. Thank you!