Skip to content

fix: memory leak in animation frame window disposal - #338263

Merged
Dmitriy Vasyura (dmitrivMS) merged 2 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-animationFrame-windowDisposal
Sep 28, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 2 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-animationFrame-windowDisposal

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

The animation-frame scheduler keeps queues and flags for each window in four global maps. Closing an auxiliary window leaves its entries behind. If the window closes before its next frame, canceled callbacks can also stay in its queue.

Change

Remove the closed window from all four maps and clear any queue currently being processed. Ignore a late frame callback after cleanup, and avoid recreating the running flag when a callback closes its own window.

Before

Opening and closing an auxiliary editor window 37 times grows each animation queue map from 3 to 40 entries. The chart shows all named-function growth rows.

before-named

After

Both animation queue maps stay at one entry for the live main window. Five unrelated named-function rows remain. The outlined menu rows disappear in this comparison, but their change has not been traced to this fix.

after-named

Test Video

test.mp4

AI disclosure: Model: GPT-6-Astra. Worktime: 14 min

Copilot AI balanced review requested due to automatic review settings September 27, 2026 20:41

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 correctly handles pending and active queues, with focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes animation-frame scheduler leaks when auxiliary windows close.

Changes:

  • Clears per-window animation queues and state during unregistration.
  • Safely ignores late frame callbacks and mid-frame window disposal.
  • Adds lifecycle, cancellation, priority, and scheduling tests.
File Description
src/​vs/​base/​browser/​dom.ts Cleans animation-frame state when windows unregister.
src/​vs/​base/​test/​browser/​animationFrame.test.ts Tests cleanup and scheduling behavior.

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

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 86a5159 into microsoft:main Sep 28, 2026
55 of 56 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-animationFrame-windowDisposal branch September 29, 2026 11:15
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Oct 1, 2026
Co-authored-by: Dmitriy Vasyura <dmitriv@microsoft.com>
(cherry picked from commit 86a5159)
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