fix: memory leak in mainThreadDocumentsAndEditors - #331170
Merged
Dmitriy Vasyura (dmitrivMS) merged 11 commits intoAug 19, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR ensures MainThreadDocumentsAndEditors properly cleans up registered editor listeners by adopting the standard Disposable pattern, and adds a regression test to confirm editor option-change listeners are removed on dispose.
Changes:
- Refactor
MainThreadDocumentsAndEditorsto extendDisposableand use_register(...)for lifecycle management. - Replace the internal editor map with a
DisposableMapso tracked editors are disposed automatically. - Add a browser test asserting editor-property change listeners stop firing after disposal.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/vs/workbench/api/test/browser/mainThreadDocumentsAndEditors.test.ts | Adds a regression test and wiring to count editor property-change notifications. |
| src/vs/workbench/api/browser/mainThreadDocumentsAndEditors.ts | Refactors disposal/lifecycle management to ensure editor listeners/resources are released. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Aaron Munger (amunger)
previously approved these changes
Aug 18, 2026
Dmitriy Vasyura (dmitrivMS)
requested changes
Aug 19, 2026
Dmitriy Vasyura (dmitrivMS)
left a comment
Collaborator
There was a problem hiding this comment.
This does not compile...
Contributor
Author
|
Dmitriy Vasyura (dmitrivMS)
requested changes
Aug 19, 2026
Copilot started reviewing on behalf of
Dmitriy Vasyura (dmitrivMS)
August 19, 2026 05:33
View session
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Dmitriy Vasyura (dmitrivMS)
August 19, 2026 05:43
View session
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
August 19, 2026 05:45
Dmitriy Vasyura (dmitrivMS)
approved these changes
Aug 19, 2026
Christof Marti (chrmarti)
approved these changes
Aug 19, 2026
Ulugbek Abdullaev (ulugbekna)
approved these changes
Aug 19, 2026
Dileep Yavanmandha (dileepyavan)
pushed a commit
that referenced
this pull request
Aug 19, 2026
* fix: dispose main thread text editors * simplify * remove whitespace * test: make editor listener assertion robust * fix * fix * fix: missing removed editors id * add unit test * simplify code * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
When restarting extensions,
MainThreadDocumentsAndEditorsleft activeMainThreadTextEditorwrappers subscribed toCodeEditorWidgetevents after their extension-host customer was disposed.Change
The main change is just this one line of code, changing
_textEditorsfrom aMapto aDisposableMap:⬇️
The other changes in the pr aren't necessarily needed. It's only to refactor the code a bit, using
extends Disposableinstead ofthis.toDispose.add.Before
When restarting extensions 37 times,
MainThreadTextEditorinstances and their editor event callbacks grow:After
No more matching
MainThreadTextEditorcallback growth is detected.Test Video
extensions-restart-7-runs.mp4