maui icon indicating copy to clipboard operation
maui copied to clipboard

Multi-window memory leak

Open vfabulokwe opened this issue 3 years ago • 1 comments

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

  1. Create new MAUI app
  2. 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);
}
  1. Click on the button
  2. Take snapshot
  3. Close window
  4. Click button again
  5. Take snapshot
  6. Close window
  7. Repeat steps 1-6 multiple times
  8. 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

vfabulokwe avatar Sep 09 '22 23:09 vfabulokwe

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.

ghost avatar Sep 13 '22 18:09 ghost

Related with https://github.com/microsoft/microsoft-ui-xaml/issues/7617

jsuarezruiz avatar Sep 28 '22 09:09 jsuarezruiz

The same problem here, any workaround?

mouralabank avatar Dec 06 '22 11:12 mouralabank

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?

danielancines avatar Dec 06 '22 16:12 danielancines