Skip to content

fix: memory leak in untitled editor resolution - #346674

Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-untitled-resolve
Nov 9, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-untitled-resolve

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

An untitled editor can be disposed while its initial contents or backup are being decoded. Resolution then creates a text model after disposal, leaving that model registered without its editor.

Change

Check disposal before resolution and again after decoding, before creating the text model.

Before

When starting resolution and disposing untitled editors 17 times, 17 additional orphan text models remain registered. Total string growth is 52,492 bytes and 2,359 strings.

Before

After

No orphan text models remain. Total string growth is 484 bytes and 13 strings over the same 17 cycles.

After

Test Video

untitled-resolve-native.webm

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

Copilot AI balanced review requested due to automatic review settings November 6, 2026 22:35

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 remain for the changes preventing orphan text models when an untitled editor is disposed during asynchronous resolution.

No open issues 🎉

What changed in this PR

Prevents orphan text models when an untitled editor is disposed before or during asynchronous resolution.

Changes:

  • Adds disposal checks before resolution and after content decoding, before creating the text model.
  • Adds regression tests for disposal before resolution, during backup resolution, and during initial-content decoding.
File Description
src/​vs/​workbench/​services/​untitled/​test/​browser/​untitledTextEditor.test.ts Adds disposal-race regression tests and restores Sinon stubs during teardown.
src/​vs/​workbench/​services/​untitled/​common/​untitledTextEditorModel.ts Guards resolution against creating text models after 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.

🟡 Changes recommended

The disposal tests do not detect unnecessary backup resolution for an already-disposed editor, and the backup-disposal test never seeds a backup to exercise its intended path.

2 open issues

Review effort: Max

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider CCR feedback.

@SimonSiefke

Copy link
Copy Markdown
Contributor Author

Added some minor test changes to address Copilot feedback!

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 identified for the untitled-editor disposal-guard change.

No open issues 🎉

2 resolved since last review

Review effort: Max

@dmitrivMS

Copy link
Copy Markdown
Collaborator
auto-merge was automatically disabled November 9, 2026 17:02

Pull request was closed

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit bc92219 into microsoft:main Nov 9, 2026
60 of 78 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 9, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-untitled-resolve 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

5 participants