Skip to content

aux window - fix setTimeout leak#311824

Merged
bpasero merged 1 commit intomicrosoft:mainfrom
andrewkchan:chan/auxwindow-leak
Apr 23, 2026
Merged

aux window - fix setTimeout leak#311824
bpasero merged 1 commit intomicrosoft:mainfrom
andrewkchan:chan/auxwindow-leak

Conversation

@andrewkchan
Copy link
Copy Markdown
Contributor

@andrewkchan andrewkchan commented Apr 22, 2026

Fixes #311823

Normally when the window is defocused, the browser will throttle any timeouts set on it. In VSCode there is a concept of aux windows, and timeouts set on the main window must not be throttled when the user is working in the aux window. There is some special code to do this in enableMultiWindowAwareTimeout by monkey-patching setTimeout in the main window + aux windows.

This code contained a memory leak where any call to setTimeout with >0 auxwindows would insert a dispose function into the main window's disposables table and never clean it up, even after calling it. I work on Cursor which is built on VSCode, and our app calls setTimeout something like 400 times per second and this was causing my app to have 230MB+ retained just by the main window disposables table.

image

Copilot AI review requested due to automatic review settings April 22, 2026 02:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a memory leak in the workbench’s multi-window setTimeout monkey-patching so timer disposables don’t accumulate in the main window’s per-window DisposableStore when auxiliary windows are open.

Changes:

  • When a timeout disposable runs, it now removes itself from the owning window’s DisposableStore using deleteAndLeak, preventing retained references after disposal.

Copy link
Copy Markdown
Contributor

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

lgtm, timeoutDisposable is added to disposables and then never gets removed for the lifetime of the window.

@bpasero could you check this out?

@pwang347 pwang347 assigned bpasero and unassigned pwang347 Apr 22, 2026
Copy link
Copy Markdown
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

Thanks

@bpasero bpasero enabled auto-merge (squash) April 23, 2026 18:08
@bpasero bpasero merged commit 1acbb74 into microsoft:main Apr 23, 2026
29 of 30 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setTimeout function leaks a disposable when any aux window is open

5 participants