Skip to content

Commit 84b0f1c

Browse files
authored
fix: tiny memory leak in debugToolBar.ts (microsoft#259349)
`dispose(IDisposable[])` call disposes every element of the array but does not clear the array itself - but it returns an empty array. As a result `debugViewTitleItems` array accumulates all items and keep references to them forever. There are two potential solutions: - `debugViewTitleItems = dispose(debugViewTitleItems)` - use DisposableStore This commit implements the second one.
1 parent c96df9d commit 84b0f1c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/vs/workbench/contrib/debug/browser/debugToolBar.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as arrays from '../../../../base/common/arrays.js';
1414
import { RunOnceScheduler } from '../../../../base/common/async.js';
1515
import { Codicon } from '../../../../base/common/codicons.js';
1616
import * as errors from '../../../../base/common/errors.js';
17-
import { DisposableStore, dispose, IDisposable, markAsSingleton, MutableDisposable } from '../../../../base/common/lifecycle.js';
17+
import { DisposableStore, markAsSingleton, MutableDisposable } from '../../../../base/common/lifecycle.js';
1818
import { Platform, platform } from '../../../../base/common/platform.js';
1919
import { ThemeIcon } from '../../../../base/common/themables.js';
2020
import { URI } from '../../../../base/common/uri.js';
@@ -392,7 +392,7 @@ export function createDisconnectMenuItemAction(action: MenuItemAction, disposabl
392392

393393
// Debug toolbar
394394

395-
const debugViewTitleItems: IDisposable[] = [];
395+
const debugViewTitleItems = new DisposableStore();
396396
const registerDebugToolBarItem = (id: string, title: string | ICommandActionTitle, order: number, icon?: { light?: URI; dark?: URI } | ThemeIcon, when?: ContextKeyExpression, precondition?: ContextKeyExpression, alt?: ICommandAction) => {
397397
MenuRegistry.appendMenuItem(MenuId.DebugToolBar, {
398398
group: 'navigation',
@@ -408,7 +408,7 @@ const registerDebugToolBarItem = (id: string, title: string | ICommandActionTitl
408408
});
409409

410410
// Register actions in debug viewlet when toolbar is docked
411-
debugViewTitleItems.push(MenuRegistry.appendMenuItem(MenuId.ViewContainerTitle, {
411+
debugViewTitleItems.add(MenuRegistry.appendMenuItem(MenuId.ViewContainerTitle, {
412412
group: 'navigation',
413413
when: ContextKeyExpr.and(when, ContextKeyExpr.equals('viewContainer', VIEWLET_ID), CONTEXT_DEBUG_STATE.notEqualsTo('inactive'), ContextKeyExpr.equals('config.debug.toolBarLocation', 'docked')),
414414
order,
@@ -424,10 +424,10 @@ const registerDebugToolBarItem = (id: string, title: string | ICommandActionTitl
424424
markAsSingleton(MenuRegistry.onDidChangeMenu(e => {
425425
// In case the debug toolbar is docked we need to make sure that the docked toolbar has the up to date commands registered #115945
426426
if (e.has(MenuId.DebugToolBar)) {
427-
dispose(debugViewTitleItems);
427+
debugViewTitleItems.clear();
428428
const items = MenuRegistry.getMenuItems(MenuId.DebugToolBar);
429429
for (const i of items) {
430-
debugViewTitleItems.push(MenuRegistry.appendMenuItem(MenuId.ViewContainerTitle, {
430+
debugViewTitleItems.add(MenuRegistry.appendMenuItem(MenuId.ViewContainerTitle, {
431431
...i,
432432
when: ContextKeyExpr.and(i.when, ContextKeyExpr.equals('viewContainer', VIEWLET_ID), CONTEXT_DEBUG_STATE.notEqualsTo('inactive'), ContextKeyExpr.equals('config.debug.toolBarLocation', 'docked'))
433433
}));

0 commit comments

Comments
 (0)