dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.63k stars 1.61k forks source link

[ios/catalyst] fix memory leak in modal pages #22089

Closed jonathanpeppers closed 16 hours ago

jonathanpeppers commented 2 weeks ago

Fixes: https://github.com/dotnet/maui/issues/20094 Context: https://github.com/AdamEssenmacher/iOSModalLeak.Maui

In the above sample, you can see that modal Page's on iOS or Catalyst live forever after they are dismissed. I was able to reproduce this issue in a device test.

After some investigation, the ContainerViewController appears to have a cycle:

After 7d0af63c was merged, this works fine when using NavigationPage, but not when using modals.

It appears after solving the cycle, the ContainerViewController goes away as well as the PageHandler and the Page.