maui
                                
                                 maui copied to clipboard
                                
                                    maui copied to clipboard
                            
                            
                            
                        Multi-window memory leak
Description
Closing a window results in a memory leak. The windows are never GC’d and often all their content is still visible within memory. Comparing this behavior with WinUI3 I have found that it works correctly in WinUI3, windows are created and recycled, counts go up, and back down. On MAUI the same process results in a steady increase in Window counts.
Steps to Reproduce
- Create new MAUI app
- Add a button in the MainPage.xaml and implement the Clicked event handler in the code behind.
// button - to open a new window
private void BlankWinLeakBtn_Clicked(object sender, EventArgs e)
{
var page = new ContentPage()
{
Content = new Label()
{
Text = ""
}
};
var win = new Window()
{
Page = page
};
    App.Current.OpenWindow(win);
}
- Click on the button
- Take snapshot
- Close window
- Click button again
- Take snapshot
- Close window
- Repeat steps 1-6 multiple times
- Compare snapshots
Expected Result: Ref count should go down when a window is closed.
Actual Result: Ref count keeps going up, window is never GC'd.
Link to public reproduction project repository
NA
Version with bug
Unknown/Other (please specify)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
All
Did you find any workaround?
No response
Relevant log output
No response
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Related with https://github.com/microsoft/microsoft-ui-xaml/issues/7617
The same problem here, any workaround?
I've been making some tests here, and the problem appears to be in a Window object that still forever allocated, in my tests, even I closed New Window and check if it removed from App.Current.Windows collection, the object never will be collect by GC and I cannot find who is locking up on the object tree. Unfortunately I didn't find any workaround for this issue, do you guys have any idea?