Skip to content

fix: memory leak extension actions - #315054

Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-extension-actions
May 30, 2026
Merged

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

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Fixes some memory leaks in extension actions.

Details

Actions can be disposable. In the case of extension actions, they are created and immediately being run. But a dispose call seems to be missing.

if(extension) {
  const action = instantiationService.createInstance(SetColorThemeAction); // disposable created
  action.extension = extension;
  return action.run(); // run, but never disposed
}

Change

The change is calling dispose after running the action:

if(extension) {
 const action = instantiationService.createInstance(SetColorThemeAction); // disposable created
  action.extension = extension;
  try {
	  return await action.run();
  } finally {
	  action.dispose(); // Ensure to dispose the action
  }

Maybe in the future this could be simplified with the new using keyword (assuming actions would have a Symbol.dispose property:

if(extension) {
  using action = instantiationService.createInstance(SetColorThemeAction); // disposable created
  action.extension = extension;
  return action.run();

Before

When opening the extension view, and right clicking on an extension and selecting "Install Another Version", then closing the quickpick 17 times, the number of InstallAnotherVersionAction and related functions seems to grow each time:

extension-install-specific-version-old

After

No more leak is detected.

Copilot AI review requested due to automatic review settings May 7, 2026 17:19

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

This PR addresses memory leaks caused by creating disposable extension-related actions (via instantiationService.createInstance(...)) and executing them without subsequently disposing them. This improves lifecycle hygiene in the Extensions UI/action flow within the workbench.

Changes:

  • Dispose InstallAnotherVersionAction after running it (and after checking its enabled state) in InstallSpecificVersionOfExtensionAction.
  • Ensure various extension context menu actions created on-demand (theme toggles, install/update toggles, etc.) are disposed after run() completes via try/finally.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/contrib/extensions/browser/extensionsActions.ts Disposes InstallAnotherVersionAction instances created transiently during “Install Specific Version…” flows (including enablement checks).
src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts Disposes transient actions created in extension context menu command handlers by wrapping run() in try/finally.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) enabled auto-merge (squash) May 30, 2026 23:38
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit c9ce2c4 into microsoft:main May 30, 2026
25 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.123.0 milestone May 30, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-extension-actions branch May 31, 2026 07:21
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants