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

Dotnet 9 Memory leaks: BindableLayout leaks if nested inside a CollectionView, CarouselView ...etc #26042

Open
GUELIANEBelkacem opened this issue Nov 21, 2024 · 3 comments
Labels
potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Milestone

Comments

@GUELIANEBelkacem
Copy link

GUELIANEBelkacem commented Nov 21, 2024

Description

After updating to .Net 9, i have 2 new memory leak behaviors:

1 ViewModel never removed if it contains a collection that is the ItemsSource of some control:**

If a ViewModel, which is the BindingContext of a page, contains a collection (List, ObservableCollection ..etc), and that collection is bound to the ItemsSource of a control (BindableLayout, CollectionView ...etc) ====> The ViewModel is never garbage collected !

I would like to specify that the control in question IS garbage collected, no issues on the display level, it's the ViewModel itself that stays in memory

This bahavior is consistent across platforms (tested Android, IOS and Windows)

To be ignored i was just a mistake on my part ^^'

2 BindableLayout nested inside another control such as CarouselView, CollectionView or another BindableLayout is never garbage collected

In this case, not only the ViewModel remains in memory, but the BindableLayout (Grid, AbsoluteLayout, StackLayout...whatever) and, of course, this leak cascades and THE ENTIRE PAGE remains in memory!!!!

This behavior is only reproducable on IOS, on Android and Windows the page is garbage collected

Might be important: The combo CollectionView inside CollectionView doesn's cause an issue, only BindableLayout inside some other collection (in my example it's a BindableLayout inside a CarouselView)

Image

Steps to Reproduce

  1. Clone the attached project and run
  2. The first issue (ViewModel leak) can be reproduced with the 2 first button (observe that, even though the pages are collected, the ViewModel itself is still in memory)
  3. The second issue (Entire page leak) can be reproduced with the 3rd button (observe that the entire page stays in memory as we have a HorizontalStackLayout with BindableLayout inside a CarouselView)

Link to public reproduction project repository

https://github.com/GUELIANEBelkacem/BindableLayoutLeakyApp.git

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.92 SR9.2

Affected platforms

iOS, Android, Windows

Affected platform versions

Latest

Did you find any workaround?

Quit my job :)

Relevant log output

@GUELIANEBelkacem GUELIANEBelkacem added the t/bug Something isn't working label Nov 21, 2024
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@GUELIANEBelkacem GUELIANEBelkacem changed the title dotnet 9 Memory leaks: ViewModel with lists always stays in memory + BindableLayout sometimes leaks Dotnet 9 Memory leaks: ViewModel with lists always stays in memory + BindableLayout sometimes leaks Nov 21, 2024
@GUELIANEBelkacem GUELIANEBelkacem changed the title Dotnet 9 Memory leaks: ViewModel with lists always stays in memory + BindableLayout sometimes leaks Dotnet 9 Memory leaks: ViewModel with lists always stays in memory + BindableLayout leaks Nov 21, 2024
@PureWeen PureWeen added the potential-regression This issue described a possible regression on a currently supported version., verification pending label Nov 21, 2024
@PureWeen PureWeen added this to the .NET 9 SR1.1 milestone Nov 22, 2024
@OvrBtn
Copy link

OvrBtn commented Nov 22, 2024

Took a quick look and if I'm looking at this right every ViewModel is being held alive by the infinite task running on worker thread
Image

Adding simple flag in ViewModel and changing it from Page's OnNavigatedFrom results in the issue being gone
Image

2024-11-22.01-59-34.mp4

Please correct me if I'm wrong 😅

@GUELIANEBelkacem
Copy link
Author

Ah yes, sorry for that it makes perfect sense. The first issue wasn't something i noticed in production code only in the test project and i found it very weird. Thank you very much!

That leaves us with the second IOS issue then (that drove me to create the test project in the first place)

@GUELIANEBelkacem GUELIANEBelkacem changed the title Dotnet 9 Memory leaks: ViewModel with lists always stays in memory + BindableLayout leaks Dotnet 9 Memory leaks: BindableLayout leaks if nested inside a CollectionView, CarouselView ...etc Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants