microsoft-ui-xaml: Memory leak in NavigationView even though I cleared the child page element while unloading.

Discussion: Why memory leak occurs while displaying a custom code snippets view in a NavigationView’s child page.

Describe the bug

While using the NavigationView control to navigate child pages, the child page’s elements were cleared in its own unloading methods. But, the child pages retaining their memory after closing them.

Steps to reproduce the bug

  1. Open and build the sample App8.zip with x86 or x64 architecture.
  2. To take a memory leak report, click the Debug menu item and select the Performance Profiler in Visual studio.
  3. Select the Memory Usage check box and click Start button
  4. Visual studio will start the diagnostic session and launching the application
  5. Click the TakeScreenshot button in the Visual Studio diagnostic session.
  6. Click on the DemoList Navigation Menu Item in the application.
  7. Click on the Code Snippets1 grid view item and its opens a code snippets page
  8. Click on the Back app bar button
  9. Repeat steps 7 and 8 for CodeSnippets 2andCodeSnippets 3
  10. Click the Empty Page Navigation Menu Item.
  11. Wait for 2 min and click the Force GC in the Visual Studio diagnostic session.
  12. Click the TakeScreenshot button in the Visual Studio diagnostic session.
  13. Then, click the Stop Collection

ezgif com-gif-maker (9)

Memory leak report:

image

image

Expected behavior

Memory should be the same or low as the initial screenshot.

Version Info

NuGet package version: [WinUI 3 - Windows App SDK 0.8: 0.8.1]

Windows app type

WinRT

Windows version

October 2020 Update (19042)

Related Links

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 5
  • Comments: 20 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Is this issue not a high priority? “WinUI 3 Gallery” and “PowerToys” also has this problem(WinAppSDK: 1.2).

Still reproducible with latest WinUI3 Gallery. Spawning additional windows from “Multiple Windows” menu and closing them not releases memory to initial state. 3 years and issue still not addressed…

@ranjeshj I have updated to 1.4.231008000 and don’t see any difference whatsoever. The GC barely cleans up anything at all. Memory build-up diminishes when approaching the 500 MB mark but it will inevitably overflow. This is still a huge issue and should be re-opened

It really is a great misfortune that such a central function as navigation still does not work without errors. It is not possible to develop professional applications with the WinAppSdk in its current state. The memory leak in the navigation in combination with the use of the WebView2 control (a new instance is created with every page change) causes every application to crash after a few days of use. I hate to think back to the day over a year ago when our team made the decision to build a new LOB application based on WinUI3.

Confirmed also with VS 17.10

Is there any news on this? It still seems to be occurring with WinApp 1.5 (and .NET 8) with a sample app I created.

@vfib memory usage still increase when more than 500 MB, but the growth will slow down. if you continue navigation, your app will crash. (tested with WinAppSDK 1.3)

Powertoys can be used for testing, navigated to difference page many times, Powertoys will crash.

Temporary solutions is:

private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
{
    System.GC.Collect();
}

Years later this is still an issue from UWP days… Is this something that can actually be solved? Or should we rather undertake the massive effort to move our years-in-the-making application to a different platform?

Even when NavigatioView is used with controls (and not with a Page), the memory used by these controls will not be released after closing the NavigationView. I tested with the NavigationView in its own UserControl. On ‘navigation’, I set the Visibility of UI elements in a <Grid> to Visible and Collapsed. So no actual navigation occurs. When I unload the NavigationView, the memory is not released. I see users getting an out of memory exception quite often now that I use NavigationView in our app.