Skip to content

fix: fix multiple window memory leaky#311415

Open
theanarkh wants to merge 1 commit intomicrosoft:mainfrom
theanarkh:fix_multiple_window_memory_leaky
Open

fix: fix multiple window memory leaky#311415
theanarkh wants to merge 1 commit intomicrosoft:mainfrom
theanarkh:fix_multiple_window_memory_leaky

Conversation

@theanarkh
Copy link
Copy Markdown

The follow steps will trigger the memory leaky.

  1. open a window.
  2. open a file.
  3. right-click on the title of the file, click move file to new window.

Copilot AI review requested due to automatic review settings April 20, 2026 17:34
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 triggered by moving an editor to a new window by ensuring multi-window-aware timeout disposables are fully deregistered from per-window disposal tracking in the workbench window implementation.

Changes:

  • Remove the per-window timeout disposable from the window’s DisposableStore when the timeout is cleared/disposed.

didClear = true;
(window as { vscodeOriginalClearTimeout?: typeof window.clearTimeout }).vscodeOriginalClearTimeout?.apply(this, [handle]);
timeoutDisposables.delete(timeoutDisposable);
disposables.delete(timeoutDisposable);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

disposables.delete(timeoutDisposable) will call timeoutDisposable.dispose() again while it's already disposing. This currently happens to be a no-op for toDisposable, but it relies on idempotent disposal and adds unnecessary reentrancy. Consider using DisposableStore.deleteAndLeak(timeoutDisposable) here to just remove the reference (since the disposable is already being disposed).

Suggested change
disposables.delete(timeoutDisposable);
disposables.deleteAndLeak(timeoutDisposable);

Copilot uses AI. Check for mistakes.
didClear = true;
(window as { vscodeOriginalClearTimeout?: typeof window.clearTimeout }).vscodeOriginalClearTimeout?.apply(this, [handle]);
timeoutDisposables.delete(timeoutDisposable);
disposables.delete(timeoutDisposable);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This change fixes a leak by removing the timeout disposable from the per-window DisposableStore, but there is no regression test asserting that the store no longer retains the disposed timeout after it fires/gets cleared. Since this behavior is subtle and easy to regress, please add a unit test in src/vs/workbench/test/browser/window.test.ts that validates the window's disposable store count returns to the original value after the multi-window timeout completes/clears.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants