-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix content pages not Garbage collected #14717
Conversation
Thank you @jsuarezruiz for the approval, although I hope you've read the Description of change because this is my first time looking at the Xamarin codebase, so any suggestions from more experienced devs would be much appreciated. Also I didn't find in the documentation how to run the CI pipeline so maybe someone with know-how and privileges could run it for me? |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Hey @danielkraut! I just triggered the pipeline :) I did read your comments and had a first quick look through your code. It seems to make sense to me so far. Thank you for this! |
Hey @danielkraut thanks for your patience on this one! I've been looking at it for a bit and seems all OK to me. If you have been digging into the more complex scenarios, feel free to do a follow up PR. Thanks for all your time and efforts on this one! |
Hi @jfversluis, yes I have been doing much more and it has been time consuming. I could not wait for this to be merged and actually did not most of the Shell advantages so in the mean time I have rewritten our application without the Shell. I have found that also not all pages are being GC'd. I though I would provide another PR but have found this - once you set Summary -
In Release build they should be but make sure you create clean build to be sure. @jfversluis Since we don't use XF Shell any more I will not test changes in this PR in production but I think that you can close issue #14657, if GC releated issues are okay in debug build. |
Thank you so much for your detailed explanation and investigation Daniel, very much appreciated! I hope you will stick with us for .NET MAUI and continue to be a contributor this way :) |
I'm not sure if anyone else is having this issue but the change on line 173 seems to be removing the TitleView from the Page. This gets triggered when switching tabs as well and when the user goes back to a tab which has a TitleView, its now gone because the code set it to null. |
Description of Change
Changes I am certail of that fixes (at least sometimes, read next paragraph) content page instances not garbage collected:
ShellToolbarTracker
- callingRemoveDrawerListener(...)
in dispose methodShellContentFragment
- explicitly setting page TitleView tonull
Shell.TitleView
(you need to add at least some layout with content, e.g.StackLayout
withLabel
)Those changes allow simple pages to be collected by GC. By simple I mean pages with default controls (buttons, labels, etc.) and with custom TitleView, but in my application I have used third-party controls (Syncfusion) and those pages are still not collected. I am certain it is a Shell issue because using those controls in non-Shell application seems fine.
Other changes don't necessarily affect my issue but are something I noticed when debugging Xamarin Forms. Calling
_shellPageContainer.Dispose();
is must-have in my opinion but calling RemoveView/RemoveAllViews is something I need more feedback from other devs if it is necessary or not.Issues Resolved
#14657 - It doesn't fix the issue completely, more investigation is still required.
API Changes
None
Platforms Affected
Behavioral/Visual Changes
Applications should use less memory because simple page instances will be garbage collected.
Before/After Screenshots
Not applicable
Testing Procedure
I was able to test only Android platform (Android 10 and 11).
In generall, just implement a finalizer on any page that is created and destroyed on the fly, i.e. a page when navigated to, a new instance is created unlike a pages which are added to flyout menu, those are usually have single instance for the lifetime of application. That finalizer is never called.
Also I have created automatic test to demonstrated the issue. Callign
PR Checklist