Skip to content

fix: memory leak in ipc.electron.ts - #317846

Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-electron-ipc
May 31, 2026
Merged

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

Conversation

@SimonSiefke

@SimonSiefke Simon Siefke (SimonSiefke) commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes a memory leak in ipc.electron.ts

Details

When a client connects, it is stored in Server.Clients. But it seems when a client disconnects, its entry from Server.Clients isn't removed.

const onDidClientReconnect = new Emitter<void>();
Server.Clients.set(id, toDisposable(() => onDidClientReconnect.fire()));

Change

The changes tries to ensure when a client disconnects, its entry from Server.Clients is removed as well.

const onDidClientReconnect = new Emitter<void>();
Server.Clients.set(id, toDisposable(() => onDidClientReconnect.fire()));

/* Ensure to remove entry from Server.Clients on disconnect  */
Event.once(onDidClientDisconnect)(() => {
	if (Server.Clients.get(id) === reconnectDisposable) {
		Server.Clients.delete(id);
	}
	onDidClientReconnect.dispose();
});

Before

When opening and closing a new window 17 times, the number of functions in ipc.electron.ts seems to grow by one each time:

window-open-new 0

After

When opening and closing a new window 17 times, no more leak in ipc.electron.ts is detected (if you look closely at the charts there is one less row):

window-open-new 5

Copilot AI review requested due to automatic review settings May 21, 2026 20:31

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 improves lifecycle management for Electron IPC clients by making reconnection handling explicit and ensuring per-client resources are cleaned up when a client disconnects.

Changes:

  • Extracted the reconnection IDisposable into a named constant for safer identity checks.
  • Added one-time cleanup on client disconnect/reconnect to remove stale Server.Clients entries and dispose the reconnect emitter.

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's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) enabled auto-merge (squash) May 31, 2026 00:03
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 58178cb into microsoft:main May 31, 2026
25 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.123.0 milestone May 31, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-electron-ipc 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.

4 participants