Skip to content

fix: memory leak in hidden status bar command arguments - #338238

Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-statusBar-hiddenCommands
Oct 7, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-statusBar-hiddenCommands

Conversation

@SimonSiefke

@SimonSiefke Simon Siefke (SimonSiefke) commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Details

Replacing the command of a hidden status bar item puts the previous command registration into a stale-registration store. That store is only cleared by a visible update, so an item that stays hidden accumulates old command arguments.

Change

Dispose superseded command registrations immediately only when they were never published to the renderer. Preserve the last published registration across hiding and hidden replacements, so queued clicks and contributed status bar items that remain visible can still execute their commands. Release published registrations through the existing visible-update or final-disposal cleanup.

Regression tests cover both hide/replacement orderings with delayed command RPCs, contributed entries updated through DidUpdate, bounded hidden-command retention, showing, and disposal. All 13 targeted status-bar and command tests pass; the new lifetime regressions fail against the original patch.

Before

Replacing a hidden status bar command 37 times adds 37 old argument objects and cleanup callbacks. The matching command-cache entries grow from 2 to 39.

before

After

No more retired-argument or matching callback growth is detected in the same 37-cycle test. The cache stays at one entry for the current command. Small unrelated object-shape differences remain.

Test Video

Seven command replacements while the status bar item remains hidden.

test.mp4

AI disclosure: Model: GPT 6 Astra. Worktime: 24 min

Copilot AI balanced review requested due to automatic review settings September 27, 2026 18:30

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.

Copilot review overview

🟢 Approval recommended

The lifecycle fix is focused and its key state transitions are covered by regression tests.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes retained command arguments when hidden status bar items replace commands.

Changes:

  • Disposes superseded hidden command registrations.
  • Clears stale registrations when hiding.
  • Adds command-lifetime regression tests.
File Description
extHostStatusBar.ts Corrects command registration cleanup.
extHostStatusBar.test.ts Tests hidden, visible, and disposal lifecycles.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two lifecycle findings from the independent review, with pinned source links and reproduction sequences below. These are source-derived findings, not live reproductions: the review gate stopped Code OSS and unit-test execution. No runtime retention counts or reproduction frequency were measured. This is a comment-only review, not an approval or request-changes decision.

Comment thread src/vs/workbench/api/common/extHostStatusBar.ts Outdated
Comment thread src/vs/workbench/api/common/extHostStatusBar.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible regression

@SimonSiefke
Simon Siefke (SimonSiefke) marked this pull request as draft October 5, 2026 16:36
@SimonSiefke
Simon Siefke (SimonSiefke) marked this pull request as ready for review October 6, 2026 22:20
@SimonSiefke

Copy link
Copy Markdown
Contributor Author

Fixed an issue with in-flight status bar commands, ensuring not to dispose their arguments too early!

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 9fcc9a1 into microsoft:main Oct 7, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 7, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-statusBar-hiddenCommands branch October 13, 2026 09:40
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-status Status bar

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants