Repository navigation
fix(android): stop fragment transition listeners from holding their transition - #11656
Merged
Merged
Conversation
…ransition A fragment transition holds its TransitionListenerImpl in Java (Transition.mListeners), and the listener held the transition back through a JS property. With wrapper resurrection the cycle was broken when the listener's wrapper was collected, but a runtime that keeps a JS-implemented object's state for as long as Java holds the object can never collect either side, so every navigation transition leaked. The entry now keeps the listener and its transition side by side, and the listener references neither the transition nor (since #11136) the entry strongly.
|
View your CI Pipeline Execution ↗ for commit e7bc65a
💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
4 of 5 tasks
edusperoni
marked this pull request as ready for review
November 20, 2026 21:45
3 of 5 tasks
NathanWalker
approved these changes
Nov 21, 2026
NathanWalker
left a comment
Contributor
There was a problem hiding this comment.
Splitting { listener, transition } onto the backstack entry (AttachedTransitionListener) cleanly breaks the Transition <-> TransitionListenerImpl Java/JS cycle while keeping both strongly reachable for the lifetime of the entry across _getTransitionState / _restoreTransitionState and _clearFragment / _clearEntry.
farfromrefug
approved these changes
Nov 21, 2026
2 of 5 tasks
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
What is the current behavior?
Each fragment transition holds its
TransitionListenerImplfrom Java (Transition.mListeners), and the listener held that transition back as a JS property (public transition):#11136 made the listener's
entryaWeakRef, which removed the path to the page, but this cycle remains. With the default wrapper lifetime, the runtime breaks it: once the listener's wrapper is unreachable from JS, it is resurrected and its Java object weakened, so the GC can collect both sides. A wrapper lifetime that keeps a JS-implemented object's state for as long as Java holds the object (the experimentalcanarymode in NativeScript/android#2127) cannot see that the cycle is garbage, so every navigation transition (the transition, its listener and their JS state) stays alive. On the automated suite this was the largest leak: at least 247 such cycles (the probe's search limit was hit), about 890 liveCustomTransitionwrappers at the end of the run.What is the new behavior?
The listener no longer references its transition.
addNativeTransitionListenerreturns{ listener, transition }, and the entry keeps that pair in its*TransitionListenerfields;_updateTransitions,_reverseTransitions, the transition-state clone and the clear functions read the transition from the pair and removepair.listener. Everything the frame uses stays reachable from the backstack entry, as before, so nothing becomes weaker under resurrection.New TRANSITIONS spec
test_Transitions_SurviveGarbageCollectionBeforeGoingBacknavigates forward with a transition, collects both heaps (gc()+java.lang.System.gc()), then goes back through the stored transitions.Verified on an Android 15 (API 35) emulator against an Android runtime built from NativeScript/android#2130 (stacked on #2127), with this change and the other Android wrapper-lifetime fixes applied together:
"wrapperLifetime": { "mode": "resurrecting" }(today's default behavior, confirmed withgetConfig("wrapperLifetimeMode")): full automated suite 1703 OK, 0 failed. The runtime counted 78,980 resurrections and 29,187 collected wrappers over the run, so the new specs ran while wrappers were being resurrected and their Java objects released."wrapperLifetime": { "mode": "canary", "scope": "all" }: full suite 1703 OK, 0 failed. After the run,findLeakCycles()reports 0 cycles, 0 leaked objects, compared with 1054 leaked objects onmain.Under
canary,CustomTransitionwrappers alive at the end of the run drop from about 890 to 100.Related: #11136