Repository navigation
fix(android): don't hold the collectionview strongly from listeners given to native code - #117
Merged
Merged
Conversation
…iven to native code The pool, recycler, adapter, scroll, touch, size, layout and pre-draw listeners, and the click listener of each cell, closed over `this` (or the cell holder) with arrow functions or `bind(this)`. A JS closure given to a native object stays alive as long as that object does, so the collectionview, its holders and their views kept each other alive: with the napi runtimes (QuickJS-ng) the JS proxies are then never finalized and every collectionview that was shown stays in memory, with its recyclerview, cells and what they hold. Capture the collectionview and the holder through a WeakRef instead. The holders stay held by `_viewHolders`, which keeps the values stored on them (view, position) alive while the collectionview is. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
farfromrefug
marked this pull request as ready for review
November 5, 2026 14:56
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.
Summary
The listeners the collectionview gives to native code closed over
this(or the cell holder). A JS closure given to a native object lives as long as that object, so the collectionview, its holders and their views kept each other alive. With the napi runtimes (QuickJS-ng) the JS proxies are then never finalized: every collectionview that was shown stayed in memory with its recyclerview, cells and what they hold.Changes
index.android.ts: capture the collectionview through aWeakRefin the closures given to native code: view pool, recycler, adapter interface (bind(this)x6), scroll, item touch, size changed, layout completed, pre-draw, item overlap decoration.WeakReftoo._viewHolders, so the values stored on them (view,position,defaultItemView) live as long as the collectionview does.Verification
tsc --noEmit -p packages/collectionview/tsconfig.jsonand prettier pass.CollectionViewCellHolder100 to 0,RecyclerView20 to 0.0,-1,false) if the collectionview is already collected, which should not happen while its native view is attached.Notes
OnTouchEventListenerclosures over the handler); not part of this PR.CustomTransitionin the NativeScript widgets (fix(android): don't reuse a CustomTransition's animator between runs Akylas/NativeScript#13), which kept every animated page alive on all runtimes.🤖 Generated with Claude Code