diff --git a/src/vs/workbench/api/browser/mainThreadDebugService.ts b/src/vs/workbench/api/browser/mainThreadDebugService.ts index 6b833ab272e..5ac499698fc 100644 --- a/src/vs/workbench/api/browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/browser/mainThreadDebugService.ts @@ -129,6 +129,11 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb const handle = this._debugAdaptersHandleCounter++; const da = new ExtensionHostDebugAdapter(this, handle, this._proxy, session); this._debugAdapters.set(handle, da); + + const d = session.onDidEndAdapter(e => { + this._debugAdapters.delete(handle); + d.dispose(); + }); return da; } diff --git a/src/vs/workbench/contrib/debug/browser/callStackView.ts b/src/vs/workbench/contrib/debug/browser/callStackView.ts index b3e3dc26f1f..08b531db334 100644 --- a/src/vs/workbench/contrib/debug/browser/callStackView.ts +++ b/src/vs/workbench/contrib/debug/browser/callStackView.ts @@ -280,7 +280,7 @@ export class CallStackView extends ViewPane { }); this.tree.setInput(this.debugService.getModel()); - + this._register(this.tree); this._register(this.tree.onDidOpen(async e => { if (this.ignoreSelectionChangedEvent) { return; @@ -461,7 +461,7 @@ export class CallStackView extends ViewPane { const contextKeyService = this.contextKeyService.createOverlay(overlay); const menu = this.menuService.createMenu(MenuId.DebugCallStackContext, contextKeyService); createAndFillInContextMenuActions(menu, { arg: getContextForContributedActions(element), shouldForwardArgs: true }, result, 'inline'); - + menu.dispose(); this.contextMenuService.showContextMenu({ getAnchor: () => e.anchor, getActions: () => result.secondary, diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index 0fad52f9739..0851c2b08a0 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -655,14 +655,16 @@ export class DebugService implements IDebugService { } } - private registerSessionListeners(session: IDebugSession): void { + private registerSessionListeners(session: DebugSession): void { const sessionRunningScheduler = new RunOnceScheduler(() => { // Do not immediatly defocus the stack frame if the session is running if (session.state === State.Running && this.viewModel.focusedSession === session) { this.viewModel.setFocus(undefined, this.viewModel.focusedThread, session, false); } }, 200); - this.disposables.add(session.onDidChangeState(() => { + const sessionStore = new DisposableStore(); + + sessionStore.add(session.onDidChangeState(() => { if (session.state === State.Running && this.viewModel.focusedSession === session) { sessionRunningScheduler.schedule(); } @@ -671,7 +673,7 @@ export class DebugService implements IDebugService { } })); - this.disposables.add(session.onDidEndAdapter(async adapterExitEvent => { + sessionStore.add(session.onDidEndAdapter(async adapterExitEvent => { if (adapterExitEvent) { if (adapterExitEvent.error) { @@ -696,6 +698,7 @@ export class DebugService implements IDebugService { } this.endInitializingState(); this.cancelTokens(session.getId()); + this.model.removeSession(session); this._onDidEndSession.fire(session); const focusedSession = this.viewModel.focusedSession; @@ -724,6 +727,8 @@ export class DebugService implements IDebugService { } this.model.removeExceptionBreakpointsForSession(session.getId()); + sessionStore.dispose(); + session.dispose(); })); } diff --git a/src/vs/workbench/contrib/debug/common/debugModel.ts b/src/vs/workbench/contrib/debug/common/debugModel.ts index 50640fcf7e5..fbb4b9abd47 100644 --- a/src/vs/workbench/contrib/debug/common/debugModel.ts +++ b/src/vs/workbench/contrib/debug/common/debugModel.ts @@ -1263,6 +1263,13 @@ export class DebugModel extends Disposable implements IDebugModel { this._onDidChangeCallStack.fire(undefined); } + removeSession(session: IDebugSession): void { + const idx = this.sessions.indexOf(session); + if (idx >= 0) { + this.sessions.splice(idx, 1); + } + } + get onDidChangeBreakpoints(): Event { return this._onDidChangeBreakpoints.event; }