Repository navigation
fix(android): keep the ListView sticky header layout listener out of a cycle - #11660
Merged
Merged
Conversation
…a cycle The sticky header's native view holds the OnLayoutChangeListener that adjusts the list padding, and the listener's arrow function captured both its own variable (to remove itself) and the ListView. The self-reference outlived the listener's removal and the ListView reference reached the header's native view; wrapper resurrection used to collect both cycles, but a runtime that keeps a JS-implemented object's state for as long as Java holds the object cannot. The listener now removes itself through `this` and reaches the ListView through a WeakRef.
|
View your CI Pipeline Execution ↗ for commit 2f92b50
💡 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:46
NathanWalker
approved these changes
Nov 21, 2026
NathanWalker
left a comment
Contributor
There was a problem hiding this comment.
Switching onLayoutChange to a method so this binds to the OnLayoutChangeListener instance and reaching ListView through a WeakRef cleanly removes both closure cycles. (Optional minor guard if ever needed: !listView?.nativeViewProtected before setPadding, though _cleanupStickyHeader already detaches the header in disposeNativeView.)
farfromrefug
approved these changes
Nov 21, 2026
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?
The sticky header's native view holds the
OnLayoutChangeListenerthat adjusts the list padding. The listener's arrow function captured both its own variable (to remove itself) and theListView:The self-reference outlives the listener's removal. With the default wrapper lifetime, the runtime collects both cycles. A wrapper lifetime that keeps a JS-implemented object's state for as long as Java holds the object (the experimental
canarymode, NativeScript/android#2127) keeps the listener, and through the closure theListView, alive for every sticky-header setup.What is the new behavior?
The listener removes itself through
this, which the runtime binds to the listener instance, and reaches theListViewthrough aWeakRef. It also removes itself if the list view is gone. Until it removes itself, the listener is held by the header's native view, as before.New LISTVIEW spec
test_stickyHeader_Android_padding_after_garbage_collectionregisters a new padding listener, collects both heaps, triggers a header layout and waits for the measured padding.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.