Maui
Maui copied to clipboard
[BUG] Popup causes the current page to leak on iOS
Is there an existing issue for this?
- [X] I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
Popup
retains a reference to current page after close.
Expected Behavior
The Popup
should not retain a reference after close.
Steps To Reproduce
- show a popup using
IPopupService
- pop the current page (shell, or navigation page doesn't matter)
- popped page is still in memory because
Popup
retains a reference to it (use aWeakReference
to verify that)
Link to public reproduction project repository
Environment
- .NET MAUI CommunityToolkit: 7.0.1
- OS: iOS 17
- .NET MAUI: 8.0.6
Anything else?
Here's an explanation of where the problem is, and a proposal on how to fix.
On iOS we're creating a ContentPage
to hold the VirtualView
.
This ContentPage
references the current page via Parent
property.
https://github.com/CommunityToolkit/Maui/blob/666f0e97ced203c8db310b1cb772c9dcb6f37f7c/src/CommunityToolkit.Maui/HandlerImplementation/Popup/Popup.macios.cs#L31
We need to clear this on close, otherwise there'll be memory leak.
Add an OnClose
handler which sets the ContentPage.Parent
property to null
.
I tested this using the debugger VirtualView.Parent.Parent = null
and it solves the memory leak.
Any news on this issue?
@albyrock87 @GUELIANEBelkacem could you please give us a hand by testing the latest version 9.0.2, and using .NET MAUI 8.0.70, and see if it fixes the memory leak? Also, if you could provide a sample repository app showing the memory leak will be fantastic, please.
thanks in advance
cc: @pictos
@vhugogarcia I can confirm latest version fixes the issue.
My library Nalu provides a leak detection mechanism which shows an alert if a page leaked after being popped.
You can use this to test also other components if you need.
See the recording demonstrating the leak of previous versions (which is now solved with 9.0.2):
Thanks @albyrock87 for the feedback and sharing the results. 😃