Skip to content

fix: memory leak in mainThreadTerminalService - #327155

Merged
Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-mainThreadTerminalService
Jul 24, 2026
Merged

Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-mainThreadTerminalService

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

When terminal data buffering starts, TerminalDataEventTracker subscribes to each terminal instance's onData event. Stopping the buffer for a disposed terminal did not dispose that source subscription, so the callback stayed reachable.

Change

The change stores each terminal instance's buffering subscription in a DisposableMap and removes and disposes it together with the terminal instance.

Before

When executing a terminal command from chat 37 times, the terminal data buffering callback grows each time (outlined in red):

chat-editor-execute-terminal-command-mainThreadTerminalService-before

After

No more leak is detected for this callback.

chat-editor-execute-terminal-command-mainThreadTerminalService-after

Test Video

chat-terminal-command-7-runs.mp4

Copilot AI review requested due to automatic review settings July 23, 2026 16:31

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.

Pull request overview

Fixes terminal data listener retention after terminal disposal.

Changes:

  • Tracks buffering subscriptions in a DisposableMap.
  • Disposes subscriptions alongside terminal instances.

@meganrogge Megan Rogge (meganrogge) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) July 23, 2026 22:55

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fix

@meganrogge
Megan Rogge (meganrogge) merged commit 716e30f into microsoft:main Jul 24, 2026
32 of 54 checks passed
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-mainThreadTerminalService branch July 28, 2026 16:51
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants