Repository navigation
fix(ios): never re-attach torn-down ListView item views - #11642
Merged
Merged
Conversation
When a cell leaves the table, ListView tears its item view down but kept the cell's WeakRef to it and left the dead native root in the cell's contentView. A later prepare of that cell re-attached the torn-down view, whose graph was no longer rooted, so native parts of it (such as the UIColor cached by a CSS Color) could already be released; the resulting exception made the data source return a nil cell and UIKit abort. UIKit also puts removed cells back into the table without asking for them again, and those rows stayed blank. Both happen constantly while an accessibility client (XCUITest, VoiceOver) disables cell reuse. - detach the item's native root from the cell on teardown - clear the cell's reference so the next prepare builds a new view - prepare a cell that is back in the table without content, from didMoveToSuperview and from willDisplay; cells UIKit announces after taking them out of the table are left alone, since preparing them would keep them in the ListView's map for good - the same teardown changes for sticky header views
|
View your CI Pipeline Execution ↗ for commit 6400534
💡 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 14, 2026 15:33
NathanWalker
approved these changes
Nov 14, 2026
cleanup nit
cleanup nit
cleanup nit
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?
On iOS, when a cell leaves the table (
willMoveToSuperview(nil)),ListViewtears its item view down (_removeContainer), but two things are left behind:cell.contentView.ListViewis not aCustomLayoutView, so removing a child doesn't detach its native view.ownerWeakRef keeps pointing at the torn-down view.If UIKit later hands that cell back,
_prepareCellre-attaches the torn-down view. Once that view left_map, nothing held its graph strongly, so native objects it caches may already have been released. One example is theUIColorcached by a CSSColor. Re-applying such a color throws insidetableView:cellForRowAtIndexPath:, the data source returnsnil, and UIKit aborts:UIKit can also put a cell it removed back into the table without calling
tableView:cellForRowAtIndexPath:again. That row stays blank.Plain scrolling doesn't hit any of this. While recycling, UIKit hides cells rather than removing them: scrolling 300 rows back and forth tore down 0 cells and used 27 in total. Under an accessibility client (XCUITest, and likely VoiceOver), UIKit effectively stops reusing cells and removes and re-adds them all the time. In one XCUITest journey a single list built 1,203 cells for 36 rows. A shop-style benchmark app with paged ListViews, driven by XCUITest, crashed within 70 seconds in both runs.
What is the new behavior?
didMoveToSuperview, and intableView:willDisplayCell:forRowAtIndexPath:for cells that are in the table.willDisplayafter they were taken out of the table are left alone. UIKit drops them, and preparing them would keep them and their item views in the list's map for good.tableView:cellForRowAtIndexPath:moves to_prepareCellForDisplay, so both paths share it.Teardown still happens as soon as a cell leaves the table. Keeping item views attached instead would pin one per cell, and with reuse disabled that reaches GB-scale memory.
Validation
Core automated iOS suite: 1,836 passed, 0 failed (iOS 26.3 simulator).
New test:
test_cell_displayed_again_after_teardown_gets_new_content_iosremoves a displayed cell from the table, sendswillDisplaywhile it is out, then puts it back. It fails onmain.Benchmark app, XCUITest leak loop (paged ListViews, about 16 min per run) with its own workaround for this bug removed:
main@nativescript/ios9.1.1Live wrapper counts at the end of the loop: the same as on
main(3ListViewCell, 29UIImage), so nothing accumulates. Live counts come from a development runtime build that can report them.Memory on an iPhone 11 Pro, over the app's standard XCUITest journey, median [min–max] in MB:
@nativescript/ios9.1.1main(3 runs)mainwas measured on a development runtime build because that build reports a released native object instead of crashing. Memory is unchanged: item views still go away as soon as their cell leaves the table.Follow-ups (not in this PR)
viewForHeaderInSection, it stays blank, as it does today.