Skip to content

fix: memory leak in modalEditorPart - #326885

Merged
Benjamin Christopher Simmonds (benibenj) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-modal-editor-part
Sep 29, 2026
Merged

Benjamin Christopher Simmonds (benibenj) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-modal-editor-part

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

When opening a modal like the new images preview, a memento seems to be created. But when closing the modal, the memento seems to be not removed.

Change

This changes it so that there is only one global memento for modals, instead of one per modal. This ensures no extra mementos are created when opening and closing a modal.

My understanding is that modalEditorPart doesn't need a memento at all, since it doesn't save any state:

protected override saveState(): void {
	return; // disabled, modal editor part state is not persisted
}

Before

When opening and closing the images modal 37 times, the number of ScopedMemento objects seems to grow by 1 each time:

modal

After

No more leak is detected.

Test Video

video-edited-2.mp4

Copilot AI review requested due to automatic review settings July 21, 2026 21:07
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Benjamin Christopher Simmonds (@benibenj)

Matched files:

  • src/vs/workbench/browser/parts/editor/modalEditorPart.ts

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.

Pull request overview

Prevents modal editor recreation from growing the global memento cache.

Changes:

  • Replaces per-instance IDs with a stable modal editor component ID.
  • Removes the modal instance counter.

Comment thread src/vs/workbench/browser/parts/editor/modalEditorPart.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues workbench-editors Managing of editor widgets in workbench window and removed triage-needed labels Sep 24, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@benibenj
Benjamin Christopher Simmonds (benibenj) merged commit 21e3d6f into microsoft:main Sep 29, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Sep 29, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-modal-editor-part branch September 29, 2026 11:15
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 workbench-editors Managing of editor widgets in workbench window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants