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
- Open and build the sample App8.zip with x86 or x64 architecture.
- To take a memory leak report, click the
Debugmenu item and select thePerformance Profilerin Visual studio. - Select the
Memory Usagecheck box and clickStartbutton - Visual studio will start the diagnostic session and launching the application
- Click the
TakeScreenshotbutton in the Visual Studio diagnostic session. - Click on the
DemoListNavigation Menu Item in the application. - Click on the
Code Snippets1grid view item and its opens a code snippets page - Click on the
Backapp bar button - Repeat steps 7 and 8 for
CodeSnippets 2andCodeSnippets 3 - Click the
Empty PageNavigation Menu Item. - Wait for 2 min and click the
Force GCin the Visual Studio diagnostic session. - Click the
TakeScreenshotbutton in the Visual Studio diagnostic session. - Then, click the
Stop Collection

Memory leak report:


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)
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:
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.