Skip to content

fix: memory leak in emitter warning names - #347966

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-emitter-warning-names
Nov 13, 2026
Merged

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

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

With workbench listener-leak warnings enabled, each emitter stores an automatically generated name even when it never needs a leakage monitor. Rebuilding Settings leaves thousands of these unused diagnostic strings in live emitters.

Change

Generate an automatic name only when creating the leakage monitor, using its existing constructor default. Preserve custom names, warning thresholds, and error handlers.

Before

When opening, splitting, and closing Settings 17 times, 5,657 emitters hold unused generated names occupying 99,064 bytes. Total string growth is 3,183,640 bytes and 21,532 strings.

Before

After

Both snapshots contain zero unused generated emitter names. Total string growth is 3,107,216 bytes and 18,298 strings; other Settings allocations remain.

After

Test Video

emitter-warning-names-native.webm

AI disclosure: Model: GPT 6.1 Sol. Worktime: 25 min

Copilot AI balanced review requested due to automatic review settings November 12, 2026 18:42

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

The test still passes with the original eager allocation, so it needs an assertion before listeners are added that unnamed emitters do not retain a generated _leakWarningName.

1 open issue
What changed in this PR

This PR reduces retained diagnostic strings in VS Code’s event emitters by deferring automatic warning-name generation until a leakage monitor is created.

Changes:

  • Removes eager automatic name allocation while preserving custom names and captured warning configuration.
  • Allows unnamed emitters to use the leakage monitor’s default name generation.
  • Adds a test for stable, distinct names in listener-leak warnings.
File Description
src/​vs/​base/​test/​common/​event.test.ts Tests generated warning-name stability and uniqueness across emitters.
src/​vs/​base/​common/​event.ts Defers automatic naming until leakage monitor creation.

Review effort: Balanced

Comment thread src/vs/base/test/common/event.test.ts Resolved

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 defer automatic emitter diagnostic naming.

No open issues 🎉

1 resolved since last review

Review effort: Max

@dmitrivMS

Copy link
Copy Markdown
Collaborator
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 2c4376d into microsoft:main Nov 13, 2026
52 of 53 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 13, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-emitter-warning-names branch November 13, 2026 10:07
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

6 participants