Skip to content

fix: memory leak in output channel disposal listeners - #338240

Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-outputService-channelDisposal
Oct 5, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-outputService-channelDisposal

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Each output channel adds its model-disposal listener to the output service lifetime store. Disposing the channel leaves that listener in the service, along with the old channel and its model.

Change

Own the model-disposal listener on the channel itself, while preserving registry removal and active-channel switching when the model is disposed.

Before

Creating, displaying, and disposing 37 output channels adds 37 old channels and models with their supporting objects. The output service listener collection grows from 26 to 63 entries.

before

After

The same 37-cycle test removes 36 of the 37 named growth rows, and the output service listener collection stays at 9 entries. One separate main-thread shutdown callback still grows by 37; the full After chart shows it. Other object-shape differences remain, so this is not a globally clean heap.

after

Test Video

Seven output-channel creation, display, and disposal cycles.

test.mp4

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

Copilot AI balanced review requested due to automatic review settings September 27, 2026 18:35

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

The leak regression assertions are skipped by the standard CI test configuration.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Moves model-disposal listener ownership to each output channel, preventing disposed channels from being retained by OutputService.

Changes:

  • Registers model-disposal listeners with channel lifetime.
  • Adds disposal, active-channel, registry, and shutdown tests.
File Description
outputServices.ts Moves disposal listener ownership to OutputChannel.
outputServices.test.ts Adds output-channel lifecycle regression tests.

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

@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues label Sep 28, 2026

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.

Two test-isolation issues from the independent review. Both are static findings: the reproduction commands below are proposed checks, not tests I have executed. I am not claiming an observed CI failure or a production-code regression.

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.

Please see comments

Save and clear pre-existing output channel descriptors before constructing the test service, then restore them after its disposal. This prevents order-dependent active-channel assertions and initialization-after-shutdown leaks when agent-session tests run first.
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 4857321 into microsoft:main Oct 5, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 5, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-outputService-channelDisposal branch October 5, 2026 16:33
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants