Repository navigation
fix(tsx): let a runtime go once its memory and instances are cleaned up - #2825
Merged
Merged
Conversation
|
This pull request has no valid
Run the checks on the head commit, fill the block in the template, then push or edit the body: this label and comment update on their own. |
Two cleanups reached the object they were registered on through the runtime, which runtime.AddCleanup never runs nor lets be collected, so every runtime that charged an allocation to its memory quota, or whose JS kept an instance of a Go class, stayed in memory for ever with all it held: each plugin closed or stopped and each sandboxed view built again. - hold's cleanup held the quota (m.release), which reaches the runtime through pin, iterate and project; it now holds the quota weakly. - bind's cleanup held the runtime (r.classes); it now holds the runtime weakly. A runtime that is gone has nothing left to release or forget, so a cleanup that finds it collected does nothing. Fixes #2823
houko
force-pushed
the
fix/tsx-memory-cleanup
branch
from
December 1, 2026 02:17
170f9d6 to
eb7354e
Compare
houko
added a commit
to yldm-tech/Kando
that referenced
this pull request
Dec 1, 2026
…go (#605) NSGo a10710d (nsgo-dev/nsgo#2825) fixes two cleanups in tsx that kept every plugin runtime that charged an allocation, or kept a Go class instance, in memory for ever. In Kando that leaked each closed, reloaded or stopped plugin and each panel built again, and made the script watchdog's memory tests fail when the package ran more than once. The range also brings nsgo-dev/nsgo#2739, which makes core.Style.FlexShrink a type of its own: every 0 becomes core.NoShrink and every 1 core.Shrink(1), and growing boxes and scroll views now shrink by default. Fixes #600
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
runtime.AddCleanupnever runs a cleanup, nor collects its object, while the object is reachable from the cleanup or its argument. Two cleanups in tsx reached their object through the runtime:hold(tsx/memory_goja.go) registeredm.release, the sandbox's quota, which keepspin, iterate, project js.Callableand so the runtime, whose JS values reach the allocation. Every runtime that charged an allocation (ArrayBuffers, typed arrays, arrays, strings ofheldMinor more) was never collected.bind(tsx/classes.go) registered a closure over the runtimerforr.classes, and the runtime's values reach the bound object. Every runtime whose JS kept an instance of a Go class was never collected.So each plugin closed, reloaded or stopped by a watchdog, and each sandboxed view built again, stayed in memory with all its JS held. In Kando, a test package whose plugin keeps about 300 MiB grew its live heap by that much per run (425, 821, 1219 MiB over
-count=3), and the watchdog's heap checks failed under the slower collections that followed.Both cleanups now hold what they need weakly; a runtime that is gone has no quota to release into and no objects to forget, so the cleanup does nothing then.
base/formula/worker_js.go's cleanup holds the worker, which holds no engine, so it is left as it is.Fixes #2823
Tests
TestMemoryLetsAClosedRuntimeGo: a runtime that charged an ArrayBuffer, a long string and an array is collected once dropped (failed before: still reachable after 10 s).TestBoundInstanceLetsAClosedRuntimeGo: a runtime whose JS keeps a bound Go instance is collected once dropped (failed before).go test -race ./tsxBuilt against main with #2824's fix to
ui/chat, which main needs to compile.