Skip to content

fix: memory leak in mainThreadTask - #331198

Open
Simon Siefke (SimonSiefke) wants to merge 11 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-mainThreadTask
Open

fix: memory leak in mainThreadTask#331198
Simon Siefke (SimonSiefke) wants to merge 11 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-mainThreadTask

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

The same AbstractTaskService is reused when the extension host restarts. Its task-system registrations kept callbacks from the old MainThreadTask instance in memory after each restart.

Change

registerTaskSystem now returns a disposable. MainThreadTask registers 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, and findExecutable callbacks per restart:

extensions-restart-before-highlighted

After

The matching task-system callback growth is gone (162 rows before, 159 unrelated rows after).

extensions-restart-after

Test Video

test.mp4

Copilot AI balanced review requested due to automatic review settings August 17, 2026 12:45

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

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.registerTaskSystem to return an IDisposable.
  • Implement unregister-on-dispose behavior in AbstractTaskService.registerTaskSystem.
  • Register the returned disposable in MainThreadTask and 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.

Comment thread src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts Outdated
Comment thread src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Comment thread src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants