Skip to content

fix(core): free the views a list of views drops past its new end - #1024

Open
iFwu wants to merge 2 commits into
nsgo-dev:mainfrom
iFwu:fix/free-dropped-list-views
Open

iFwu wants to merge 2 commits into
nsgo-dev:mainfrom
iFwu:fix/free-dropped-list-views

Conversation

@iFwu

@iFwu iFwu commented Nov 20, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1021.

A list of views cut back to fewer reused its array and left the views it dropped in the slots past its new end, so each stayed in memory, and through it the whole subtree it was in, until the list grew back that long. Each list now clears the slots it no longer uses, as accessories, canvases and labels already do.

  • core/commit.go: syncChildren clears the old children past the new end; commitRound clears laidOut before reusing it.
  • core/tree.go: Tree.clear and setChildren clear what is past the region's new end; mountText's SpansFunc effect clears the spans before building them again.
  • core/ops.go: setText clears the element's old children and spans.
  • core/list.go (second commit): updateLists clears the tree's list of lists past the lists still live, which kept a removed List while another list stayed; it showed once an app moved its chat transcripts to List.
  • core/core_test.go: TestViewsDroppedFromListsAreFreed drops views from each kind of list (an Each's rows, a Dynamic's views, an element text's and a SpansFunc text's attachments, views with an OnLayout, a List), then checks that they are collected. It fails on main in all six cases. Reverting any one of the eight changes alone fails at least one case.
  • CHANGELOG.md: an Unreleased line.

This touches core/tree.go next to #1008's change in discard, and core/list.go's updateLists, apart from #1027's change in updateList; each pair merges cleanly apart from the CHANGELOG.md line each adds at the end of Unreleased.

Targets

  • Shared code (core, base, ui, tsx, the nsgo tool)
  • macOS
  • iOS
  • tvOS
  • watchOS
  • Android
  • Windows
  • Linux
  • Web
  • Mini programs
  • Docs or website only

Screenshots

None.

Verification

  • go tool nsgo test -run '^TestViewsDroppedFromListsAreFreed$' ./core fails on main at c70af8a7 in all six cases (row2 stays in memory, view2 stays in memory, box0 stays in memory twice, heard0 stays in memory, list stays in memory) and passes with both commits, three runs in a row.
  • go tool nsgo check on Linux x86_64 (the host): passes, before and after the second commit.
  • go tool nsgo test on Linux x86_64 under Xvfb (GDK_BACKEND=x11, GSK_RENDERER=cairo), with the first commit: 3,070 passed, 8 failed, 59 skipped. The same 8 fail on main in the same environment (3,069 passed): TestAccessibilitySelectedAndExpandedReachATSPI (no AT-SPI registry), TestVideoShowsWhatIsBehindItsTransparentPixels (no GStreamer plug-in for the alpha WebM), TestInstanceDefaultPathStaysCompatible (the socket path passes the address limit under this run's long TMPDIR), TestEditorsTakeLinesLimitsAndSubmit (the submit count in the window title stays 0 under Xvfb), and TestDevPagesTakeTheTokenOutOfTheirAddress, TestWebHostChannel, TestWebStrictCSP and TestWebDevClientKeepsItsToken, which get no answer from the browser or DevTools here. With the second commit, go tool nsgo test ./core: 760 passed.
  • The branch merges cleanly with main at c06fa6f4, whose only change to these files since c70af8a7 is fix(core): avoid full resolves for window environment reports #1000's in core/tree.go.
  • In a headless nsgotest soak of a desktop app on v0.2.0 with this change and two similar ones for out-of-flow boxes and edge bars, no removed node stayed reachable in any of ten scenarios over 300 cycles each; without them, reading a long chat transcript back and returning to its end kept about 9,600, and switching between transcripts laid out in Lists kept the one left, about 770 nodes, through the tree's list of lists. On macOS (Apple M3, macOS 27.2.1) the app's count of live views stayed flat over a 10-minute series of heap profiles.
  • Not run: -target tests, as nothing here is backend-specific; Windows, web and Apple's mobile targets.

Checklist

  • The title is a Conventional Commit, such as fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.
  • Docs whose facts change are updated, and CHANGELOG.md's Unreleased has a line for a capability users can see.
  • New third-party code, assets and dependencies name their source and license.

A list of views cut back to fewer reused its array and left the views it dropped in the slots past its new end, so each stayed in memory, and through it the whole subtree it was in, until the list grew back that long: a view's children synced to fewer (syncChildren), a Dynamic or Show built again with fewer views (clear), an Each with fewer rows (setChildren), a text's attachments set again or dropped by SpansFunc (an element's children and spans, and the spans SpansFunc builds again), and the views told their layout in the last commit (laidOut). A chat list that mounts a few hundred rows while scrolled back and drops all but the last few dozen at its end kept every dropped row, close to 100 MB in a headless run. Each list now clears the slots it no longer uses, as accessories, canvases and labels already do.

Fixes nsgo-dev#1021
@github-actions github-actions Bot added size/M documentation Improvements or additions to documentation core bug Something isn't working and removed size/M labels Nov 20, 2026
updateLists filtered t.lists in place and left the lists it dropped in the
slots past its new end, so a removed List stayed in memory, and through it
the whole subtree it was in, while another list stayed. It now clears what
is past the lists still live, as the other lists of views do.

Fixes nsgo-dev#1021

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core documentation Improvements or additions to documentation size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: views dropped from a list of views stay in memory in the slots past its new end

1 participant