Skip to content

fix: memory leak in integrated browser element handles - #338247

Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-browserElement-remoteHandles
Sep 28, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 1 commit into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-browserElement-remoteHandles

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Adding a browser element to chat creates a temporary remote object handle while extracting its details. That handle is never released, so removing the attachment and DOM element leaves the old element state in the browser process.

Change

Release the temporary handle after extraction finishes, including when extraction fails. Preserve the original result or error if the frame disappears during cleanup.

Before

Adding an element to chat, removing the attachment, and removing the DOM element 37 times adds 37 old selected-element state objects.

before

After

No more selected-element state growth is detected in the same 37-cycle test. Separate WeakRef wrapper growth disappears after garbage collection; unrelated native and string growth remains in the broader diagnostic.

Test Video

Seven element selection, attachment removal, and DOM removal cycles in the integrated browser.

test.mp4

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

Copilot AI balanced review requested due to automatic review settings September 27, 2026 19:11
@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/browserViewFrameInspector.ts
  • src/vs/platform/browserView/test/electron-main/browserViewFrameInspector.test.ts

Joaquín Ruales (@jruales)

Matched files:

  • src/vs/platform/browserView/electron-main/browserViewFrameInspector.ts
  • src/vs/platform/browserView/test/electron-main/browserViewFrameInspector.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

🟢 Approval recommended

The cleanup is correctly scoped and comprehensively tested without changing extraction results or errors.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes a remote object handle leak during integrated-browser element extraction.

Changes:

  • Releases temporary CDP handles in a failure-safe finally block.
  • Adds tests for success, failure, asynchronous extraction, and cleanup errors.
File Description
browserViewFrameInspector.ts Releases temporary element handles after extraction.
browserViewFrameInspector.test.ts Verifies handle lifecycle and error preservation.

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

@dmitrivMS Dmitriy Vasyura (dmitrivMS) added freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues browser-integration Web browsing features integrated into VS Code (e.g., integrated browser) and removed triage-needed labels Sep 28, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit f5e3fca 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-browserElement-remoteHandles branch September 29, 2026 11:15
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Oct 1, 2026
)

Fix temporary browser element remote handle disposal

(cherry picked from commit f5e3fca)
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