Massive memory leak in CollectionView while scrolling
See original GitHub issueDescription
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
Issue Analytics
- State:
- Created a year ago
- Reactions:14
- Comments:9 (2 by maintainers)
Top Results From Across the Web
ios - How to avoid the memory issue while scrolling an ...
I'm displaying lot of images (5k images) in UICollectionView . These images has been download from remote server. When I scroll from top...
Read more >Memory leak in ListView when the ItemsSource has changed
Note: It is possible the memory leak is caused by the bindings holding objects longer than necessary. Similar memory leaks can be reproduced ......
Read more >Experiencing memory leak using UICollectionView and ...
In one of my views, I use UICollectionView to display album art for all albums in the library. When scrolling I'm getting huge...
Read more >The Most Common Issues I've Caught Reviewing iOS Apps
If you need something other than a vertically scrolling list of rows, a collection view covers those other cases. They are extremely memory...
Read more >UIDragItem causes memory leak when…
I have a CollectionView with Drag and Drop and Context Menu functionality. There's a memory leak caused by returned [UIDragItem] array in ItemsForBeginning ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve been testing memory leak issues with this app.
These should fix this:
(I marked the last one to close this when merged)
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