Skip to content

fix: memory leak in terminal horizontal scrollbars - #338241

Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-terminalInstance-horizontalScrollbar
Sep 28, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-terminalInstance-horizontalScrollbar

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Switching a terminal back from content width removes and disposes its horizontal scrollbar, but leaves the scrollbar in the terminal lifetime store. Repeated toggles keep the old scroll widgets and their DOM state until the terminal closes.

Change

Remove and dispose the scrollbar through the terminal store when content width is disabled and during terminal disposal.

Before

Toggling terminal content width on and off 37 times adds 37 old scroll widgets, their scrollbars, state, and callbacks. The terminal store grows from 2 to 39 discarded scrollbar entries.

before

After

No more matching scrollbar or scroll-state growth is detected in the same 37-cycle test. The terminal store has no discarded scrollbar entries. Small unrelated DOM-cache and array differences remain in the full heap comparison.

Test Video

Seven content-width toggles on a terminal containing a long line.

test.mp4

AI disclosure: Model: GPT 6 Astra. Worktime: 33 min

Copilot AI balanced review requested due to automatic review settings September 27, 2026 18:43
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
  • src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts

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 fix is correct and covered by focused regression tests, with only a minor comment-format issue noted.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Fixes retained terminal horizontal scrollbars by removing them from the terminal’s lifetime store when disposed.

Changes:

  • Deletes scrollbars through DisposableStore.
  • Adds lifecycle and repeated-toggle regression tests.
File Description
terminalInstance.ts Corrects scrollbar disposal ownership.
terminalInstance.test.ts Adds scrollbar lifecycle regression coverage.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts Outdated
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues label Sep 28, 2026
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the terminal General terminal issues that don't fall under another label label Sep 28, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 142d5cc into microsoft:main Sep 28, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Sep 28, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-terminalInstance-horizontalScrollbar branch September 29, 2026 11:15
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Oct 1, 2026
* fix: release disposed terminal horizontal scrollbars

* test: shorten terminal scrollbar sandbox comment

---------

Co-authored-by: Dmitriy Vasyura <dmitriv@microsoft.com>
(cherry picked from commit 142d5cc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues terminal General terminal issues that don't fall under another label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants