CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Memory leak during page navigation with ListViews

Open manodasanW opened this issue 2 years ago • 14 comments

Find attached two demo projects, the "UIOnly" folder contains the example from this issue comment, ported to the latest project template. Additionally, the "MVVM" folder contains an example that is similar to what I try to build in my application. I had to click back and force for a long time and some memory gets freed sometimes, but the app will crash eventually. image

Hope that helps and thanks for looking into it.

PoC.zip

Originally posted by @marcpiechura in https://github.com/microsoft/CsWinRT/issues/413#issuecomment-1016580898

manodasanW avatar Jun 29 '22 23:06 manodasanW

Hi, I created a project using the starter WinUI3 template provided by Visual Studio. Here it is. I also provided a gif demonstrating how every navigation adds a MB and it never stops nor gets collected. 2022-06-29_19-28-01 This is on .NET 6.0.300, template used was navigation pane with a settings page, MSIX packaging, and MVVM structure. This is also demonstrated via the newest WinUI 3 Gallery update from the Microsoft Store, clicking a new navigation tab adds several MB every time.

TheAvonian avatar Jun 29 '22 23:06 TheAvonian

Hi, I created a project using the starter WinUI3 template provided by Visual Studio. Here it is. I also provided a gif demonstrating how every navigation adds a MB and it never stops nor gets collected. 2022-06-29_19-28-01 2022-06-29_19-28-01 This is on .NET 6.0.300, template used was navigation pane with a settings page, MSIX packaging, and MVVM structure. This is also demonstrated via the newest WinUI 3 Gallery update from the Microsoft Store, clicking a new navigation tab adds several MB every time.

has the same problem, operation similar to yours.(also appears when navigation stack is disabled)
repo: https://github.com/l619534951/NavMemLeak
I don't know whose problem it is, then I created issue in microsoft-ui-xaml https://github.com/microsoft/microsoft-ui-xaml/issues/7322

brandon3343 avatar Jul 06 '22 04:07 brandon3343

Along with rendering performance issues and the consistent memory leakages. WinUI3/WinAppSdk has been performing really badly since its release. Can we expect any significant improvements in both rendering & memory? Or should we switch to web dev?

christosk92 avatar Sep 21 '22 01:09 christosk92

is there any workaround for this while we wait for the fix ? I am surprise this has not been fix yet as this affects everyone using this framework. Even WinUI 2 Galery has this issue. Come on.

KWodarczyk avatar Oct 24 '22 17:10 KWodarczyk

We have migrated our UWP app to WinUI3/WinAppSdk and all our users are reporting a significant performance improvement, there are still memory leaks in navigation, but in our stress tests they do not appear as early as they did in UWP. This team is doing a good job but these remaining issues need to be addressed soon, the navigation memory leaks have been present on this platform since its early days.

asierpn avatar Oct 25 '22 05:10 asierpn

For now I went ahead and implemented ContentControl navigation instead of Frame navigation. Manually disposing/getting rid of UserControl (instead of pages) seems to be doing the trick for now.

christosk92 avatar Nov 02 '22 08:11 christosk92

For now I went ahead and implemented ContentControl navigation instead of Frame navigation. Manually disposing/getting rid of UserControl (instead of pages) seems to be doing the trick for now.

Try Windows App SDK 1.2.0-preview2, It fixes many problems. (The memory leak of listview is fixed, but I haven't tested Frame)

brandon3343 avatar Nov 02 '22 08:11 brandon3343

@l619534951 I'm using it, it's not fixed.

bogdan-patraucean avatar Nov 02 '22 08:11 bogdan-patraucean

It should be fixed in the latest WindowsAppSDK version. I tested navigating back & forth and it's indeed increasing the memory but for my app it stops at around 500 MB of RAM. As far as I know there is a cache limit until which no memory will be released, so probably that's why it's still increasing.

bogdan-patraucean avatar Dec 15 '22 23:12 bogdan-patraucean

Yes it has been fixed. Memory does no longer increase beyond a certain threshold (I believe this is dependent on the System configuration and automatically adapts).

I believe WinAppSdk is heading in the right direction with the latest improvements in rendering. But scrolling still isn't as smooth as UWP, but I believe this will be fixed in a future release.

I already have a much better experience with my app using WinAppSDK than with UWP, no sudden crashes, ListView/ItemsRepeater renders are much faster etc.

Well done to the team.

christosk92 avatar Dec 18 '22 13:12 christosk92

I have still this issue.

@christosk92 my application runs with 110mb memory usage, I have several charts and after doing some navigation and loading some charts it goes to 2gb and more.

Is this certain threshold you mentioned above may goes higher than this or I should be hopeful to see it stop growing somewhere ?

Reza-Noei avatar Oct 30 '23 18:10 Reza-Noei

@christosk92 Which version resolved this problem?

soroshsabz avatar Nov 02 '23 08:11 soroshsabz

@manodasanW I think this issue is not only related to ListView (maybe rename this issue?) and I also would argue it is not really fixed. Apps like Files or the WinUI Gallery still have issues with massive memory consumption.

Attached is a simple repro project: NavigationMemoryLeak.zip

marcelwgn avatar Nov 10 '23 19:11 marcelwgn

@manodasanW any update?

soroshsabz avatar Nov 10 '23 21:11 soroshsabz