Memory leak when close window in winUI3

Khoa Bui 51 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 App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
694 questions
{count} votes

Accepted answer
  1. Roy Li - MSFT 31,276 Reputation points Microsoft Vendor
    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.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

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