Skip to content

fix: memory leak in integrated browser inspector sessions - #338228

Merged
Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-browserViewInspector-sessions
Sep 28, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 4 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-browserViewInspector-sessions

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

When a cross-site iframe closes, the integrated browser removes its frame inspector but leaves the session event listener in the browser inspector's disposable store. The session and its callbacks remain there until the whole browser closes.

Change

Group event and close listeners by session and dispose that group when the session closes. Ignore late session results and attachments after disposal.

Before

Creating and removing a cross-site iframe 37 times adds 37 old DebugSession objects and two sets of 37 callbacks in the main process.

before

After

No more inspector-session or matching callback growth is detected in the same 37-cycle test.

Test Video

Seven iframe creation and removal cycles in the integrated browser.

test.mp4

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

Copilot AI balanced review requested due to automatic review settings September 27, 2026 17:55
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Kyle Cutler (@kycutler)

Matched files:

  • src/vs/platform/browserView/electron-main/browserViewInspector.ts
  • src/vs/platform/browserView/test/electron-main/browserViewInspector.test.ts

Joaquín Ruales (@jruales)

Matched files:

  • src/vs/platform/browserView/electron-main/browserViewInspector.ts
  • src/vs/platform/browserView/test/electron-main/browserViewInspector.test.ts

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

🟡 Changes recommended

The late evaluation-result path needs a regression test to prevent reintroducing stale session retention.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes inspector-session listener retention when cross-origin iframes close.

Changes:

  • Tracks listeners in per-session disposable stores.
  • Cleans listeners on session closure and ignores late asynchronous results.
  • Adds lifecycle-focused unit tests.
File Description
browserViewInspector.ts Adds session-scoped listener cleanup.
browserViewInspector.test.ts Tests session and inspector disposal behavior.

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

Comment thread src/vs/platform/browserView/electron-main/browserViewInspector.ts
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the browser-integration Web browsing features integrated into VS Code (e.g., integrated browser) label Sep 28, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 9c965cd into microsoft:main Sep 28, 2026
55 of 56 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Sep 28, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-browserViewInspector-sessions branch September 29, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

browser-integration Web browsing features integrated into VS Code (e.g., integrated browser) freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants