Skip to content

.NET MAUI Shell app page navigation memory leaks #15930

@duffh

Description

@duffh

Description

In a .NET MAUI Shell app running on Windows it looks like pages are held in memory after navigating to and then away from the page. This results in an increase in memory over time as pages are opened and closed.

We noticed this issue as we have some particularly memory intensive pages that result in steep memory jumps as they are opened and closed.

Steps to Reproduce

Setup

  1. Create new Maui app. File -> New Solution -> Maui App
  2. Create two new MAUI ContentPages SecondaryPage and TertiaryPage
  3. Add SecondaryPage to the Shell Flyout Items
  4. Add a Button to the SecondaryPage with a clicked event await Navigation.PushAsync(new TertiaryPage());

Testing

  1. Run the app targeting Windows
  2. Navigate to the SecondaryPage via the Flyout
  3. Navigate to the TertiaryPage via the Button on SecondaryPage
  4. Click the back button
  5. Take a snapshot of the memory usage
  6. Navigate to the TertiaryPage via the Button on SecondaryPage
  7. Click the back button
  8. Take a snapshot of the memory usage
  9. Repeat as many times as desired

Result: Looking at the memory usage snapshots the number of instances of TertiaryPage in memory increases with the number of times the page has been opened.

image

image

Expected: The page should no longer exist in memory after navigating away, the number of instances in memory should not increase as the page is repeatedly opened.

Link to public reproduction project repository

https://github.com/duffh/MauiMemoryLeakTestApp

Version with bug

8.0.0-preview.5.8529

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Windows SDK 10.0.19041.0

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Labels

area-controls-shellShell Navigation, Routes, Tabs, Flyoutperf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)platform/windowss/try-latest-versionPlease try to reproduce the potential issue on the latest public versions/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions