Memory leaks when replacing Application.Current.MainPage by a new one keep the old page in memory #23034
Labels
area-controls-general
General issues that span multiple controls, or common base classes such as View or Element
fixed-in-8.0.80
fixed-in-9.0.0-preview.7.24407.4
memory-leak 💦
Memory usage grows / objects live forever (sub: perf)
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
Description
I created a new MAUI app from scratch, removed the Shell and created 2 ContentPages named Page1 and Page2.
In Page1, I just placed a button that calls
Application.Current.MainPage = new Page2();
In Page2, I started a thread with a serie of GC.Collect();
After memory analysis, I saw that Page1 is kept in memory.
Steps to Reproduce
Create a new MAUI application
Remove the Shell and the page created by the wizard
Create a new content page and name it Page2.
In code behind, in the ctor, start a new thread like this:
new Thread(async () => { await Task.Delay(5000); GC.Collect(); GC.Collect(); GC.Collect(); }).Start();
Create a new content page an name it Page1
In Page1, add a button with this statement in the click event handler:
Application.Current.MainPage = new Page2();
In App.xaml.cs, replace the shell by
MainPage = new Page1();
The issue is similar with 8.0.60 SR6
MauiApp1.zip
Link to public reproduction project repository
No response
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
Windows, I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
Not yet
Relevant log output
No response
The text was updated successfully, but these errors were encountered: