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 with CollectionView #14993

Open
THoferSchmitz opened this issue May 9, 2023 · 10 comments
Open

Memory Leak with CollectionView #14993

THoferSchmitz opened this issue May 9, 2023 · 10 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/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.)
Milestone

Comments

@THoferSchmitz
Copy link

Description

Hi,

I wrote a small tool to download a radio stations playlist for me to look through, very small and simple, and it works. But for some reason for a little over 1k items (less than 3Mb database file size) the app needs more than 1Gb of memory. So there is either a memory leak I don't see, I'm using the CollectionView in a way than I shouldn't or there is a bug somewhere in MAUI / CollectionView

Steps to Reproduce

My app is a new MAUI project in VS, only the MainPage files were modified, I didn't want to spread this little code over multiple files. Code is in the repo.

On first startup (no db file) it starts at ca. 120Mb, goes up when I use the parse button to 140Mb and the moment the CollectionView loads the files it blows up to more than 1Gb.

Link to public reproduction project repository

https://github.com/THoferSchmitz/Playlist-Downloader

Version with bug

6.0.312

Last version that worked well

6.0.312

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Windows SDK 10.0.17763.0

Did you find any workaround?

No response

Relevant log output

No response

@THoferSchmitz THoferSchmitz added the t/bug Something isn't working label May 9, 2023
@jsuarezruiz jsuarezruiz added platform/windows 🪟 legacy-area-perf Startup / Runtime performance area-controls-collectionview CollectionView, CarouselView, IndicatorView labels May 9, 2023
@SarthakB26
Copy link

SarthakB26 commented May 9, 2023

Yes its a memory leak I am also having this issue on android though. It generally happens when items being added/removed from a CollectionView very frequently rather then fixed data source that load only once.
So basically you will see memory increase for each add/remove/update operation in ColletionView ItemSource

Might be related to
#14664

@THoferSchmitz
Copy link
Author

This might be related, depending on the underlying cause. However, I do not replace my ItemSource over and over. This increase (1Gb memory for a 3Mb database) happens on the very first assignment of the property that ItemSource has a binding to. Pressing the parse button again, causing a reassignment of the ItemSource, it will rise to more than 2Gb memory. So I do see that issue as well, however, my initial memory usage is already much bigger than it should be.

@SarthakB26
Copy link

I would suggest try ListView with HasUnevenRow="False" if possible Or one of below

https://github.com/roubachof/Sharpnado.CollectionView
https://github.com/Redth/Maui.VirtualListView

@Dreamescaper
Copy link

Dreamescaper commented May 9, 2023

VerticalStackLayout does not constraint its content, therefore your CollectionView grows infinitely, rendering all the items at once.
Use Grid instead of VerticalStackLayout, and remove the outer ScrollView (it won't be needed).

@Dreamescaper
Copy link

Duplicate of #8097.

@THoferSchmitz
Copy link
Author

I didn't know about the issue with VerticalStackLayout. That helped a little. I don't remember seeing that in the CollectionView docs last time I looked.

However, I would still say it needs to much memory. There are less than 2k items, and they only have a string and an int property and two very small commands. Of course the Collectionview needs the template every time, but even with that the memory usage seems very excessive.

@mattleibow mattleibow added this to the Backlog milestone May 10, 2023
@ghost
Copy link

ghost commented May 10, 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.

@mattleibow
Copy link
Member

@jonathanpeppers would this b better with all the perf work you are doing?

@jonathanpeppers
Copy link
Member

I think someone should just retest this one w/ main or .NET 8 where we have the fix:

@samhouts samhouts added the memory-leak 💦 Memory usage grows / objects live forever label Aug 1, 2023
@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jan 17, 2024
@Zhanglirong-Winnie
Copy link

Memory leak issue, we verified this issue with Visual Studio Enterprise 17.9.0 Preview 2.1. Can repro on windows platform with sample project.
https://github.com/THoferSchmitz/Playlist-Downloader
image

@rachelkang rachelkang added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Jan 23, 2024
@Eilon Eilon added t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) and removed legacy-area-perf Startup / Runtime performance labels May 10, 2024
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/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage 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

10 participants