question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak when use x:Bind in winUI3

See original GitHub issue

Describe the bug

Hi, BlankPage.Xaml code:

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

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? Also, I tried with Bindings.StopTracking(); but doesn’t work.

Also asked at: https://docs.microsoft.com/en-us/answers/questions/898874/memory-leak-when-close-window-in-winui3.html Thanks

Steps to reproduce the bug

Click to open and close BlankPage window and resource of BlankPage’s view is not released.

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.1.1

Windows app type

  • UWP
  • Win32

Device form factor

No response

Windows version

No response

Additional context

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
HO-COOHcommented, Aug 3, 2023

I just want to help to make this not get closed

0reactions
github-actions[bot]commented, Jul 28, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak when close window in winUI3
BlankPage will be released as normal and no memory leak happened. So, is it a problem on x:Bind?
Read more >
UWP compiled binding x:Bind produces memory leaks
Work around for this issue is to explicitly call Bindings.StopTracking() at page Unloaded event handler. It's because compiled bindings doesn't ...
Read more >
Memory leak in UWP {x:Bind ...} compiled bindings : r/dotnet
Compiled bindings in UWP have a serious problem - it leaks memory because of totally unclear reason. Here some discussion on stack overflow....
Read more >
Avoiding memory leaks
New Win2D resources are allocated each time the app moves to a different page, but the old ones are never freed so memory...
Read more >
Troubleshooting Memory Issues
Uno Platform provides a set of classes aimed at diagnosing memory issues related to leaking controls, whether it be from an Uno.UI issue...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found