Skip to content

Only remember sticky scroll mouse targets inside the widget - #337855

Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
mainfrom
agents/leak-sticky-scroll-mouse-target
Sep 25, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 3 commits into
mainfrom
agents/leak-sticky-scroll-mouse-target

Conversation

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Related to #146841

Every StickyScrollController (one per code editor) listened to mousemove on the main window and stored mouseEvent.target in _mouseTarget — for any element in the window. When the element under the mouse was part of an editor view that got detached afterwards (e.g. the tab was switched with the keyboard), every sticky scroll controller kept that span and, through its parent chain, the complete detached view alive until the mouse moved again.

_mouseTarget is only used to find the hovered sticky line, so only targets inside the sticky scroll widget are remembered now.

Retainer path (heap snapshot):
StickyScrollController._mouseTarget → <span class="mtk21"> → <span> → view-line → view-lines → … → <div class="monaco-editor">

Measurement

Scenario Without this change With this change
Rest the mouse over editor text, switch tabs with Ctrl+PageUp 1 detached editor view, 1,059 DOM nodes 0

Bounded (one tree, released on the next mouse move), but independent of which editor had the controller: every open editor's controller retained it.

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.

Every StickyScrollController stored the target of every mousemove in the window, which retained arbitrary DOM nodes, e.g. of an editor view that got detached afterwards. Only targets inside the sticky scroll widget are used.

Related to #146841

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings September 25, 2026 00:27
@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 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 leak fix is focused and correct; only a minor comment-format issue remains.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Limits sticky-scroll mouse tracking to widget-owned elements, preventing detached editor DOM retention.

Changes:

  • Filters global mouse targets using the sticky-scroll widget boundary.
  • Clears the stored target when the pointer is elsewhere.
File Description
stickyScrollController.ts Restricts retained mouse targets to sticky-scroll DOM.

💡 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 e182159 into main Sep 25, 2026
35 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the agents/leak-sticky-scroll-mouse-target branch September 25, 2026 01:55
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Sep 27, 2026
…t#337855)

* Only remember sticky scroll mouse targets inside the widget

Every StickyScrollController stored the target of every mousemove in the window, which retained arbitrary DOM nodes, e.g. of an editor view that got detached afterwards. Only targets inside the sticky scroll widget are used.

Related to microsoft#146841

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

* Condense sticky scroll mouse target comment

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

---------

Co-authored-by: Copilot <[email protected]>
(cherry picked from commit e182159)
@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-sticky-scroll 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