-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Page-level memory leak in NavigationPage on iOS #20119
Comments
Would the area/perf label be appropriate here as well? This issue causes entire pages (and possibly nav stacks) not to be GC'ed, which causes noticeable performance degradation once the app starts needing swap space, and ultimately leading to forced app termination. |
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
Can repro this issue at iOS platform on the latest 17.10 Preview 6(8.0.3/8.0.21). |
Fixes: dotnet#20119 PR dotnet#13833 fixed a leak in child pages of a `NavigationPage`, but it appears there are several cycles that would prevent the `NavigationPage` itself from going away. So, if you did something like this: // The original NavigationPage & children leak Application.Current.MainPage = new NavigationPage(new Page1()); Application.Current.MainPage = new Page2(); I could reproduce the same problem in a new device test. The cycles (and solutions) are: 1. `NavigationPage` -> `NavigationRenderer` -> `ParentingViewController` -> `NavigationPage` * Solution: make `_child` a `WeakReference` 2. `NavigationPage` -> `MenuItemTracker` -> `NavigationPage` * Solution: make `_target` a `WeakReference`, and `_additionalTargets` a `List<WeakReference>` 3. `NavigationPage` -> `MenuItemTracker.CollectionChanged` -> `NavigationPage` * Solution: subscribe/unsubscribe in `WillMoveToParentViewController` After these changes the sample app works, and the new device test passes.
Fixes: dotnet#20119 PR dotnet#13833 fixed a leak in child pages of a `NavigationPage`, but it appears there are several cycles that would prevent the `NavigationPage` itself from going away. So, if you did something like this: // The original NavigationPage & children leak Application.Current.MainPage = new NavigationPage(new Page1()); Application.Current.MainPage = new Page2(); I could reproduce the same problem in a new device test. The cycles (and solutions) are: 1. `NavigationPage` -> `NavigationRenderer` -> `ParentingViewController` -> `NavigationPage` * Solution: make `_child` a `WeakReference` 2. `NavigationPage` -> `MenuItemTracker` -> `NavigationPage` * Solution: make `_target` a `WeakReference`, and `_additionalTargets` a `List<WeakReference>` 3. `NavigationPage` -> `MenuItemTracker.CollectionChanged` -> `NavigationPage` * Solution: subscribe/unsubscribe in `WillMoveToParentViewController` After these changes the sample app works, and the new device test passes.
* [ios/catalyst] fix leak in NavigationPage Fixes: #20119 PR #13833 fixed a leak in child pages of a `NavigationPage`, but it appears there are several cycles that would prevent the `NavigationPage` itself from going away. So, if you did something like this: // The original NavigationPage & children leak Application.Current.MainPage = new NavigationPage(new Page1()); Application.Current.MainPage = new Page2(); I could reproduce the same problem in a new device test. The cycles (and solutions) are: 1. `NavigationPage` -> `NavigationRenderer` -> `ParentingViewController` -> `NavigationPage` * Solution: make `_child` a `WeakReference` 2. `NavigationPage` -> `MenuItemTracker` -> `NavigationPage` * Solution: make `_target` a `WeakReference`, and `_additionalTargets` a `List<WeakReference>` 3. `NavigationPage` -> `MenuItemTracker.CollectionChanged` -> `NavigationPage` * Solution: subscribe/unsubscribe in `WillMoveToParentViewController` After these changes the sample app works, and the new device test passes. * Skip test on Windows for now
Description
NavigationPages are on iOS are not garbage collected after being removed.
Page-level leaks are serious, as they prevent child elements (in this case, whole child pages) from being collected as well.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/AdamEssenmacher/iOSNavigationPageLeak.Maui
Version with bug
8.0.3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 17.2
Did you find any workaround?
Calling
DisconnectHandler()
on the NavigationPage's Handler before removing it from use will prevent the navigation page and its children from leaking.Relevant log output
No response
The text was updated successfully, but these errors were encountered: