Skip to content

fix: memory leak in pixel ratio window disposal - #338257

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

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

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

A pixel-ratio monitor listens once for any window to close, then checks the window ID. If another window closes first, that consumes the listener, leaving the monitor and its window in the global monitor map when its own window closes.

Change

Keep the unregister listener until its own window closes, then dispose the listener and monitor and remove the map entry.

Before

Opening two auxiliary editor windows, closing the first, and then closing the second 37 times grows the monitor map from 3 to 40 entries. PixelRatioMonitorImpl, DevicePixelRatioMonitor, and NativeAuxiliaryWindow each grow by 37.

before

After

The monitor map stays at one entry for the live main window. Pixel-ratio monitors and NativeAuxiliaryWindow no longer grow; 15 unrelated growth rows remain, including font caches and menu actions.

after

Test Video

test.mp4

AI disclosure: Model: GPT-6-Astra (investigation and implementation), GPT-6 (PR preparation). Worktime: approximately 51 min

Copilot AI balanced review requested due to automatic review settings September 27, 2026 19: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

🟡 Changes recommended

The primary regression tests are skipped during normal CI because exposed garbage collection is unavailable.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes pixel-ratio monitor cleanup when unrelated auxiliary windows close first.

Changes:

  • Retains unregister listeners until their matching window closes.
  • Adds regression tests for multi-window disposal ordering.
File Description
src/​vs/​base/​browser/​pixelRatio.ts Corrects monitor disposal lifecycle.
src/​vs/​base/​test/​browser/​pixelRatio.test.ts Adds lifecycle regression tests.

💡 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 4485486 into microsoft:main Sep 28, 2026
36 of 38 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-pixelRatio-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
* fix: release pixel ratio monitors when their window closes

* test: verify pixel ratio cleanup without explicit GC

(cherry picked from commit 4485486)
@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants