Skip to content

Memory leak while repeatedly navigating between pages #10578

@Vroomer

Description

@Vroomer

Description

Recurring navigation to a page and back causes memory leak. It can lead to extreme degradation in performance in a case of an app that uses TabbedPage with complex Views that contain a lot of controls.

In the app I'm developing I have a CollectionView of items which can be opened by user to show detailed information. The user has to be able to do such action hundreds of times during a session. However there seems to be something lingering in the memory which can't be collected by GC and isn't properly disposed.

I made a simple example consisting of two pages. The app is made so that you can easily push and pop a page. The pushed page consists only of a simple CollectionView.

  • Tested on MAUI 7.0.0-rc.1.6683.
  • The issue happens in Windows. I don't have the opportunity to test other platforms right now.
  • The problem occurs with both Shell and standard page navigation.
  • When there is no control on the pushed page, there is no leak.
  • It doesn't seem to apply only to CollectionView.
  • Instances of pages are kept in memory even after popping them. Triggering GC successfully collects them except for the last instance - not sure that is ideal.

Steps to Reproduce

  1. Load the repository and run the app.
  2. Repeatedly push and pop the page using the first button while observing memory usage in ResMon/memory profiler.
  3. Click on the "Force GC" button to trigger GC - it will free some memory, but the memory leak should be apparent. You will also see text output from WeakReferences to pushed pages and their collections.

Link to public reproduction project repository

https://github.com/Vroomer/MAUI-navigation-memory-leak.git

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows SDK 10.0.22000

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Labels

area-navigationNavigationPagefixed-in-8.0.0-preview.4.8333Look for this fix in 8.0.0-preview.4.8333!perf/generalThe issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)platform/windowst/bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions