Skip to content

fix: memory leak in terminal replay - #338252

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-terminalReplay-serializeAddon
Sep 28, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-terminalReplay-serializeAddon

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Reattaching a terminal creates a new serialization add-on to replay its screen. Each add-on is added to the PTY host's terminal, but is not removed after serialization. Repeated reconnects grow that terminal's add-on list.

Change

Dispose the serialization add-on after screen serialization or reuse of a saved screen.

Before

Detaching and reattaching the same terminal 37 times leaves 37 extra serialization add-ons:

before

After

No more serialization add-on growth is detected in the same 37-cycle test. The terminal's add-on list stays at two entries.

Test Video

test.mp4

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

Copilot AI balanced review requested due to automatic review settings September 27, 2026 19:33
@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/platform/terminal/node/ptyService.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

🟡 Changes recommended

Cleanup is skipped when serialization throws, leaving the leak possible on retries.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes terminal replay memory growth by cleaning up temporary serialization add-ons.

Changes:

  • Disposes replay serialization add-ons after use.
  • Adds regression tests for repeated serialization and saved-screen reuse.
File Description
src/​vs/​platform/​terminal/​node/​ptyService.ts Adds serialization add-on cleanup.
src/​vs/​platform/​terminal/​test/​node/​ptyService.test.ts Verifies cleanup and replay output.

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

@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 bf900e0 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-terminalReplay-serializeAddon 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: dispose terminal replay serialization addons

* Simplify terminal replay addon disposal

* fix: dispose replay serialization addon when serialization fails

(cherry picked from commit bf900e0)
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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