Skip to content

fix(android): hold the TextBase from its text transformation weakly - #11662

Merged
edusperoni merged 1 commit into
mainfrom
fix/android-text-transformation-owner
Nov 22, 2026
Merged

edusperoni merged 1 commit into
mainfrom
fix/android-text-transformation-owner

Conversation

@edusperoni

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

text-transform (any value but initial) and a Button's formatted text install a TextTransformationImpl on the native TextView. The transformation held its TextBase in a strong textBase property, and the TextBase reaches the TextView again through its native view:

TextView --mTransformation--> TextTransformationImpl --(JS) textBase--> TextBase --nativeView--> TextView

Tearing a view down breaks the cycle from the JS side, so the cycle only lasts for views that are never torn down. One case is the previous root after Application.resetRootView(): resetActivityContent unloads it but does not tear down its UI. With the default wrapper lifetime, the runtime breaks the cycle anyway: once the transformation's wrapper is unreachable from JS, it is resurrected and its Java object weakened. A wrapper lifetime that keeps a JS-implemented object's state for as long as Java holds the object (the experimental canary mode, NativeScript/android#2127) cannot, so the old root stays alive through every transformed label or formatted-text button in it.

The new RESET-ROOT-VIEW spec resets to a layout root holding a Label with text-transform: uppercase and a Button with formatted text, then resets away from it. Without this change, findLeakCycles() (NativeScript/android#2130) reports, in both the extended and all scopes:

StackLayout --ViewGroup.mChildren--> View[] --[]--> StyleableTextView --TextView.mTransformation--> TextTransformationImpl --ns:record--> JS Object --textBase--> JS Label --parent--> JS StackLayout --_androidView--> JS StackLayout wrapper --ns:wrapper--> StackLayout
android.widget.Button --TextView.mTransformation--> TextTransformationImpl --ns:record--> JS Object --textBase--> JS Button --_androidView--> JS android.widget.Button wrapper --ns:wrapper--> android.widget.Button

This is the same class of cycle as #11658 (Button and ActionBar listener owners), and belongs on that PR's list of remaining strong owners.

What is the new behavior?

TextTransformationImpl holds the TextBase through a WeakRef. Once the view is gone, getTransformation returns the text it was given unchanged. The transformation itself is still held by the TextView, and the TextBase by the view tree, so nothing it needs becomes weaker under resurrection.

New TEXT-BASE spec test_android_text_transform_survives_garbage_collection sets text-transform on a Label and formatted text on a Button, then collects both heaps (gc() + java.lang.System.gc() + runFinalization()). It then changes the text, requests a layout and checks what the transformation returns (CHANGED, and the updated span text).

Verification

Android 15 (API 35) emulator, with an Android runtime built from NativeScript/android#2130 (stacked on #2127):

Related: #11658

@nx-cloud

nx-cloud Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit fe646be

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 31s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 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 2026-11-22 19:01:07 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11662
npm i https://pkg.pr.new/@nativescript/vite@11662
npm i https://pkg.pr.new/@nativescript/webpack@11662

commit: fe646be

@edusperoni
edusperoni marked this pull request as ready for review November 20, 2026 21:46

@NathanWalker NathanWalker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holding TextBase via WeakRef in TextTransformationImpl and returning charSeq unchanged if collected cleanly breaks the TextView -> TextTransformationImpl -> TextBase -> TextView cycle on undisposed roots after resetRootView, while keeping live Label text-transform and Button formattedText updates working across GC.

@NathanWalker NathanWalker added this to the 9.2 milestone Nov 21, 2026
@edusperoni

Copy link
Copy Markdown
Contributor Author

@copilot fix conflicts

Copilot AI commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@copilot fix conflicts

Resolved the conflict and merged main in 55da749.

A TextView holds the TextTransformationImpl that text-transform and a
Button's formatted text install (TextView.mTransformation), and the
transformation held its TextBase in a strong textBase property, which
reaches the TextView again through the view's native view. Only tearing
the view down broke that cycle, so a view that is never torn down, such
as the previous root after Application.resetRootView(), stayed alive
once wrapper resurrection no longer collected it. The transformation
now holds the TextBase through a WeakRef and returns the text unchanged
once it is gone.
@edusperoni
edusperoni force-pushed the fix/android-text-transformation-owner branch from 55da749 to fe646be Compare November 22, 2026 18:53
@edusperoni
edusperoni merged commit 4f92046 into main Nov 22, 2026
10 checks passed
@edusperoni
edusperoni deleted the fix/android-text-transformation-owner branch November 22, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants