Memory leak when close window in winUI3

Khoa Bui 56 Reputation points
2022-06-22T09:04:10.64+00:00

Hi,
BlankPage.Xaml code:

<Grid>  
    <Button Click="{x:Bind click_event}" />  
</Grid>  

BlankPage.xaml.cs code:

private void click_event(object sender, RoutedEventArgs e)  
{  
    int a = 1;  
}  
~BlankPage1()  
{  
    int a = 1;  
}  

From main window, I open BlankPage window and close it:

private  ButtonClick()  
        {  
            var aa = new BlankPage1();  
            aa.Activate();  
            aa.Close();  
            aa = null;  
            GC.Collect();  
        }  

However, BlankPage object doesn't released (doesn't run into ~BlankPage function). And if you continue click to open and close the BlankPage, memory keeps increasing.

Otherwise, if I don't use x:Bind in BlankPage.xaml:

<Button Click="click_event" />  

BlankPage will be released as normal and no memory leak happened.

So, is it a problem on x:Bind? Or, Do i need to do something like unbinding before closing?

Thanks

Windows development | Windows App SDK

Answer accepted by question author
Anonymous
2022-06-27T07:44:02.893+00:00

Hello,

Welcome to Microsoft Q&A!

I've tested this on my side. From the snapshot of the memory usage, I could clearly see the Windows Class is not reducing after the GC and even after a long time when using the x:Bind. But when setting the click event normally, the snapshot shows the Windows Class that was created will be released. This might be an issue for Windows App SDK. Please submit an issue on Github for this: https://github.com/microsoft/microsoft-ui-xaml/issues

Thank you.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Khoa Bui 56 Reputation points
    2022-06-27T08:40:54.477+00:00

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.