Page-level memory leak on modal navigation on iOS
AdamEssenmacher opened this issue · 4 comments
Description
Pages pushed modally on iOS are not garbage collected after being popped, resulting in the modal page leaking.
Page-level leaks are serious, as they prevent child elements from being collected as well.
Steps to Reproduce
- Push page modally
- Pop modal page
- Force GC runs
- Observe modal page never collected
Link to public reproduction project repository
https://github.com/AdamEssenmacher/iOSModalLeak.Maui
Version with bug
8.0.6
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS / MacOS
Affected platform versions
iOS 17.2
Did you find any workaround?
No response
Relevant log output
No response
Having same issue using Navigation.PushAsync(). When page is popped from the stack, objects on the popped ContentPage are not collected. On iOS, the app is quickly jettisoned due to excessive RAM usage. Seeing the issue on Windows and Mac Catalyst in addition to iOS.
@fischberg I opened this issue because I have good reason to believe that there is leak in modal navigation itself, specifically on iOS.
It's a more general problem in MAUI apps where would-be small leaks spread through entire pages and make them uncollectible by the GC--but that's not necessarily an issue specific to navigation. It sounds like your problem may fall in to this category.
The MAUI repo has an in-depth discussion on memory leaks on the wiki: https://github.com/dotnet/maui/wiki/Memory-Leaks
I'm personally working on a toolkit that can help detect and mitigate these general-case leaks, while also helping us isolate leaks to the offending component: https://github.com/AdamEssenmacher/MemoryToolkit.Maui
Can repro this issue at iOS platform on the latest 17.10 Preview 4(8.0.6&8.0.20).
Just found something else that could very well be related.
If a XAML element has an assigned name (e.g. x:Name="Something"
) inside a page that's being displayed modally, that element will leak.
I have a hunch this behavior will go away once the modal page leak does. I can check once the fix is in the nightly builds.