Repository navigation
fix(android): hold the SegmentedBar from its tab content factory weakly - #11657
Merged
Merged
Conversation
|
View your CI Pipeline Execution ↗ for commit b094934
💡 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: |
edusperoni
marked this pull request as ready for review
November 20, 2026 21:45
NathanWalker
approved these changes
Nov 21, 2026
NathanWalker
left a comment
Contributor
There was a problem hiding this comment.
Holding SegmentedBar via WeakRef in TabContentFactoryImpl with the androidUtils.getApplicationContext() fallback in createTabContent cleanly breaks the _tabContentFactory <-> owner cycle while preserving lazy tab creation across GC.
farfromrefug
approved these changes
Nov 21, 2026
SegmentedBar keeps its TabContentFactoryImpl in _tabContentFactory, and the factory kept the bar in a strong owner property, which disposeNativeView never cleared. Wrapper resurrection used to break this cycle; a runtime that keeps a JS-implemented object's state for as long as Java holds the object cannot, so every SegmentedBar and its view subtree stayed alive. The factory now holds the bar through a WeakRef and falls back to the application context once the bar is gone.
edusperoni
force-pushed
the
fix/android-segmented-bar-factory-cycle
branch
from
November 22, 2026 18:53
90ff841 to
b094934
Compare
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?
SegmentedBarkeeps itsTabContentFactoryImplin_tabContentFactory, and the factory kept the bar as a strongowner.disposeNativeViewclears the tab-change listener's owner but never the factory's:The cycle runs through the factory's native counterpart (Java also holds the factory in each
TabSpec). With the default wrapper lifetime, the runtime breaks it once the factory's wrapper is unreachable from JS. A wrapper lifetime that keeps a JS-implemented object's state for as long as Java holds the object (the experimentalcanarymode, NativeScript/android#2127) cannot, so everySegmentedBarstays alive, along with everything it references. That is 18 bars on the automated suite, even when disposed normally.What is the new behavior?
The factory holds the bar through a
WeakRef, likeTabView'sPagerAdapter. If the bar is gone when Android asks for tab content, it returns the same collapsedTextView, built on the application context. The factory itself is still held by the bar and by Java, as before, and the bar is held by its parent, so nothing it needs becomes weaker under resurrection.New SEGMENTED-BAR spec
test_SelectingTabsAfterGarbageCollection_CreatesTheirContentcollects both heaps between tab selections, which makesTabHostcreate tab content lazily through the factory.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.