Clear IntersectionObserver reference on dispose#5831
Open
srid wants to merge 1 commit intoxtermjs:masterfrom
Open
Clear IntersectionObserver reference on dispose#5831srid wants to merge 1 commit intoxtermjs:masterfrom
srid wants to merge 1 commit intoxtermjs:masterfrom
Conversation
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
Fixes the IntersectionObserver retention path from #5820 without using
WeakRef.RenderService._registerIntersectionObservercurrently creates an observer whose callback closes overthis. The disposable disconnects the observer, but the disposable closure also keeps a JS reference to the observer. Since the observer owns its callback, the disposedRenderServicecan remain reachable through:RenderService -> MutableDisposable -> disposable closure -> IntersectionObserver -> callback -> RenderServiceStore the observer on
RenderServiceinstead, and have the disposable disconnect and null out that field. The disposable no longer captures the observer object, so after dispose there is no JS-land reference from the disposed service back to the observer/callback pair.This is an alternative to #5821's
WeakRefversion.Evidence
Kolu reproduced the original leak on the pre-#617 UI and compared three arms in Chrome DevTools MCP. Each arm used a fresh
just dev, 7 terminals created/restored through the UI, and 30 Focus<->Canvas round trips via the visible header toggle.Uint32Array +339,JSArrayBufferData +339Uint32Array +0,JSArrayBufferData +0Uint32Array +0,JSArrayBufferData +0The baseline reproduced the retained xterm-buffer signature. Both WeakRef and this observer-nullify variant retained zero additional xterm buffer arrays.
Caveat: this MCP run did not reproduce the original +367 MB magnitude because the clean UI-created/restored terminals had only ~118 scrollback rows instead of the large restored buffers from the production repro. The retention signature still distinguishes the baseline from both fixes.
Test
npm run lint-changesCloses #5820