fix: memory leak in mainThreadTask - #331198
Open
Simon Siefke (SimonSiefke) wants to merge 11 commits into
Open
Conversation
…ry-leak-mainThreadTask
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 makes task system registrations disposable so callers can unregister task systems automatically (e.g., when the registering component is disposed).
Changes:
- Change
ITaskService.registerTaskSystemto return anIDisposable. - Implement unregister-on-dispose behavior in
AbstractTaskService.registerTaskSystem. - Register the returned disposable in
MainThreadTaskand add a test to verify disposal unregisters task systems.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/vs/workbench/contrib/tasks/common/taskService.ts | Updates the task service interface to return an IDisposable for task system registrations. |
| src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts | Returns a disposable that removes task system info from the internal registry on dispose. |
| src/vs/workbench/api/browser/mainThreadTask.ts | Registers the task system disposable so it’s cleaned up when MainThreadTask is disposed. |
| src/vs/workbench/api/test/browser/mainThreadTask.test.ts | Adds a unit test ensuring task system registrations are disposed/unregistered. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
The same
AbstractTaskServiceis reused when the extension host restarts. Its task-system registrations kept callbacks from the oldMainThreadTaskinstance in memory after each restart.Change
registerTaskSystemnow returns a disposable.MainThreadTaskregisters it for cleanup, so its callbacks are unregistered when the instance is disposed.Before
Restarting extensions 37 times retained one additional set of
uriProvider,resolveVariables, andfindExecutablecallbacks per restart:After
The matching task-system callback growth is gone (162 rows before, 159 unrelated rows after).
Test Video
test.mp4