maui
maui copied to clipboard
.Net 8/ 9 Memory leaks
Description
We are having some memory issues in our app where the app gets slower after some time and noticed in a gcdump file that all our pages have multiple counts.
We created a dummy project with a second transient page, and added a buton with a method to go back, and call dispose method as well. However in the gcdump there are still multiple counts of this page.
Our question is how are transient pages managed in .NET MAUI? We tested in .net 8 and 9 Transient View/ViewModels are not cleaned up.
How do static variables affect memory management in .NET MAUI? If I am injecting a Singleton Service into a ViewModel will this be cleaned up or also the service has to be transient?
This is a basic default project with no viewmodels and minimal dependency injection, so what is causing the page to be kept in memory?
Steps to Reproduce
- Open referenced repo
- Create a gcdump file after opening and closing the second page
- See multiple counts of Second Page
Link to public reproduction project repository
https://github.com/Zack-G-I-T/MauiMemoryIssue
Version with bug
9.0.0-rc.2.24503.2
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response