Skip to content

Release widget DOM nodes when an editor view is disposed - #337853

Merged
Dmitriy Vasyura (dmitrivMS) merged 2 commits into
mainfrom
agents/leak-editor-widget-dom-view-parts
Sep 25, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 2 commits into
mainfrom
agents/leak-editor-widget-dom-view-parts

Conversation

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Related to #146841

Content, overlay and glyph margin widgets outlive the editor View: CodeEditorWidget keeps them and re-adds them to the next view once a model is attached. When a model is detached without a new one (e.g. all editors of a group are closed, the editor stays around without a model), the widgets' DOM nodes stayed parented in the disposed view — or in its overflowingContentWidgets/overflowingOverlayWidgets containers, which live outside the view's DOM. Since the widgets are referenced by live contributions (rename, suggest, hover, sticky scroll, …), the entire previous view DOM stayed alive.

ViewContentWidgets, ViewOverlayWidgets and GlyphMarginWidgets now remove the DOM nodes of their widgets on dispose. Attaching a new model adds them to the new view as before.

Retainer path (heap snapshot):
StickyScrollController → StickyScrollWidget._rootDomNode → <div class="sticky-widget"> → overlayWidgets → overflow-guard → <div class="monaco-editor"> (same for RenameWidget, SuggestWidget, HoverWidget via the overflowing containers)

Measurement

Scenario Without this change With this change
Open a file, show rename (F2) and suggest widgets, run Close All Editors 1 detached editor view, 1,402 DOM nodes + 95 nodes of overflowing widget containers 0
Same, closing the group's editors with Ctrl+K W 1,443 + 95 nodes 0

One retained view per editor control that is left without a model (e.g. per empty editor group), until a model is attached again.

How this was measured

Code OSS (Electron, dev build) driven over CDP with Playwright. After each scenario: 4× forced GC, then DOM.getDetachedDomNodes (the data behind Edge's Detached Elements tool), counting the descendants of every detached root. "Without this change" means all other fixes from this series applied and only this one reverted, so the number shows what this retainer alone keeps alive. Each scenario was run 3 times with identical results. The retainer was identified from a heap snapshot retainer path.

Added a CodeEditorWidget test with a real view: widget nodes (incl. an overflowing content widget) are released on setModel(null) and reattached on the next setModel.

Content, overlay and glyph margin widgets outlive the editor view and are only moved into the next view once a new model is attached. Until then their DOM nodes stayed parented in the disposed view (or its overflowing widget containers) and kept the whole previous view DOM alive, e.g. for editors of hidden editor groups.

Related to #146841

Co-authored-by: Copilot <[email protected]>
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues label Sep 25, 2026
Copilot AI balanced review requested due to automatic review settings September 25, 2026 00:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The lifecycle cleanup is correct and regression coverage exercises the affected widget types.

Review effort: Balanced
Findings: 3 Low severity

Open (3)
What changed in this PR

Prevents editor widget DOM nodes from retaining disposed editor views.

Changes:

  • Detaches content, overlay, and glyph-margin widget nodes during view disposal.
  • Verifies nodes detach and reattach across model changes.
File Description
contentWidgets.ts Releases content widget nodes.
overlayWidgets.ts Releases overlay widget nodes.
glyphMargin.ts Releases glyph-margin widget nodes.
codeEditorWidget.test.ts Tests detachment and reattachment.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit b5faf95 into main Sep 25, 2026
35 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the agents/leak-editor-widget-dom-view-parts branch September 25, 2026 01:47
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Sep 27, 2026
…37853)

* Release widget DOM nodes when an editor view is disposed

Content, overlay and glyph margin widgets outlive the editor view and are only moved into the next view once a new model is attached. Until then their DOM nodes stayed parented in the disposed view (or its overflowing widget containers) and kept the whole previous view DOM alive, e.g. for editors of hidden editor groups.

Related to microsoft#146841

Co-authored-by: Copilot <[email protected]>

* Condense widget release comments

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
(cherry picked from commit b5faf95)
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

editor-window Issues around editor window UI freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants