Skip to content

iOS PopModalAsync causes memory leaks #21453

@dalux-era

Description

@dalux-era

Description

Whne you push a modal page that is wrapped in a NavigationPage
Navigation.PushModalAsync(new NavigationPage(new ModularPage())); on iOS we can see that the Page is never released from the memory. We are using Perfiew for debugging.

Here is a GCDump where we open and close a modal page multiple times
20240326_110245_0.zip

I am adding a sample which has both solutions outcommented. Seems counterintuitive that we need to call DisconnectHandler on existing pages and controls when popping a page from the Navigation stack.

NavigationSample.zip

Steps to Reproduce

  1. Open sample app
  2. Start profiling
  3. Press the "Click me" button
  4. Press "Close" button
  5. Repeat steps 3 and 4
  6. MAke a memory GCdump

Link to public reproduction project repository

No response

Version with bug

8.0.6 SR1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

Seems that this can only be fixed by running disconnectHanler on each element on the Page including the page

page.Handler?.DisconnectHandler();

MyLayout.Handler?.DisconnectHandler();

Handler?.DisconnectHandler();

or creating a custom handler for the NavigationPage and running

ViewController.Dispose();
var viewController = ViewController as PageViewController;
viewController.CurrentView = null;

Relevant log output

No response

Metadata

Metadata

Labels

area-controls-modalfixed-in-8.0.70fixed-in-9.0.0-preview.6.24327.7legacy-area-perfStartup / Runtime performancemigration-compatibilityXamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convertpartner/cat 😻this is an issue that impacts one of our partners or a customer our advisory team is engaged withperf/generalThe issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)perf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)platform/ioss/triagedIssue has been reviewedt/bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions