Skip to content

fix: memory leak in comment thread disposal - #338216

Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-commentThread-disposal
Sep 29, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 1 commit into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-commentThread-disposal

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Disposing a comment thread removes it from the editor but leaves it in its live comment controller’s thread map. The old thread, comments, and update state remain there until the controller is disposed.

Change

Remove each regular or template thread from its controller’s map when the thread is disposed. Clear the cleanup callback after disposal and make repeated disposal a no-op while preserving other live threads.

Before

Creating, displaying, and disposing a comment thread 37 times adds 37 old threads and comment payloads across 24 named growth rows. The live controller’s thread map grows from 2 to 39 entries.

before

After

No more matching thread or comment growth is detected in the same 37-cycle test. The controller’s thread map stays empty, and all 24 named growth rows disappear. Small unrelated object-shape differences remain.

Test Video

Seven review-thread creation, display, and disposal cycles while the comment controller stays active.

test.mp4

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

Copilot AI balanced review requested due to automatic review settings September 27, 2026 17:46

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 cleanup is scoped, idempotent, and adequately covered without identified regressions.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes comment-thread memory retention in live controllers.

Changes:

  • Removes disposed regular and template threads from controller bookkeeping.
  • Makes repeated disposal idempotent.
  • Adds lifecycle and memory-retention tests.
File Description
src/​vs/​workbench/​api/​common/​extHostComments.ts Cleans up thread mappings during disposal.
src/​vs/​workbench/​api/​test/​common/​extHostCommentThreads.test.ts Tests disposal, isolation, renderer interaction, and garbage collection.

💡 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
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the comments Comments Provider/Widget/Panel issues label Sep 29, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 480c6e1 into microsoft:main Sep 29, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Sep 29, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-commentThread-disposal branch September 29, 2026 11:15
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

comments Comments Provider/Widget/Panel issues 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.

7 participants