Skip to content

fix: memory leak in debouncedObservable - #346498

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-debouncedObservable
Nov 7, 2026
Merged

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

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

When a peek editor closes, its inline chat affordance removes its observers from the debounced selection. The pending debounce timer is not cancelled.

Change

Cancel the pending debounce timer and reset its handle when the last observer is removed.

Before

When opening and closing a TypeScript peek definition 37 times, InteractionEmitter grows from 22 to 64:

before

After

No more leak detected.

Test Video

typescript-peek-definition.webm

AI disclosure: Model: GPT-6.1 Sol. Worktime: 26 min

Copilot AI balanced review requested due to automatic review settings November 6, 2026 09:32

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.

🟡 Changes recommended

A fake-timer regression test is still needed to verify that removing the last observer cancels pending debounce delivery and prevents stale values after resubscription.

1 open issue
What changed in this PR

This PR fixes pending debounce timer cleanup in VS Code’s shared observable utilities, addressing retained state after a peek editor’s inline chat observers are removed.

Changes:

  • Cancel the pending debounce timer when the last observer is removed.
  • Reset the timer handle alongside the existing cached-value cleanup.
File Description
src/​vs/​base/​common/​observableInternal/​utils/​utils.ts Clear and reset the pending timer during debouncedObservable disposal.

Review effort: Balanced

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.

🟢 Approval recommended

No active review issues are reported for the change to cancel pending debounce work when the last observer detaches.

No open issues 🎉

1 resolved since last review

Review effort: Max

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 89d0dd3 into microsoft:main Nov 7, 2026
51 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 7, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-debouncedObservable branch November 11, 2026 10:35
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