Repository navigation
Clear karaxEvents after detaching handlers to stop per-redraw closure leak - #303
Merged
Merged
Conversation
… leak removeAllEventHandlers called removeEventListener for each recorded handler but never emptied the karaxEvents bookkeeping array, so every re-attach cycle (mergeEvents, once per event-carrying node per redraw) appended another wrapped-handler tuple forever. Each leaked closure pins its render generation's whole VNode tree via wrapEvent's captured n, and the detach loop re-walks the growing array on every redraw. Adds a regression case to tests/difftest.nim driving mergeEvents 10x against a stub event target: karaxEvents must not grow. Fixes karaxnim#302
Xenosians
added a commit
to Xenosians/agenticFrontend
that referenced
this pull request
Nov 4, 2026
A long-lived Janus tab grew by about 10 MB a minute while idle and a 25-minute browser acceptance run took Chromium past 3 GB, exhausting WSL. Karax 1.5.0 removes a button's old listeners on every redraw but never clears its record of them, so each record keeps every earlier closure and, through them, every earlier render tree alive (34 handlers per button after 20 health reads in the new test). Pin Karax to upstream commit fa5fdef (karaxnim/karax#303, merged), which resets that record after removing the listeners. The application code is unchanged; app.js and docs.js are rebuilt from source. The new browser test fails against Karax 1.5.0 (35 handlers per button) and passes with the pinned commit. Full FE gate: 28/28 browser suites, 218 Nim units, 35 node tests; exit 0.
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.
Fixes #302
removeAllEventHandlersdetaches each handler recorded in the node'skaraxEventsbookkeeping array (added in the #139 fix) but never emptiesthe array, while
addEventShellappends on every attach. SinceupdateElementrunsmergeEventsfor every visited event-carrying node onevery redraw, each such node accumulates one wrapped-handler tuple per
redraw, forever:
VNode tree via
wrapEvent's capturedn;The fix resets the array after detaching. One line, plus a regression case
in
tests/difftest.nim(runs in the existingnim js -d:nodejs -r tests/difftest.nimCI step): it drivesmergeEvents10× against a stubevent target and asserts
karaxEventsdoesn't grow. On unpatched master itfails with "karaxEvents grew to 11 entries after 10 event re-merges";
with the fix the suite passes.