fix some, but not all leaks wrt DebugSession

This commit is contained in:
Johannes
2023-08-31 16:46:25 +02:00
parent 6b49d155ca
commit 170f7cd76e
4 changed files with 22 additions and 5 deletions
@@ -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;
}
@@ -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,
@@ -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();
}));
}
@@ -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<IBreakpointsChangeEvent | undefined> {
return this._onDidChangeBreakpoints.event;
}