From 96c3dbc1d45ac08f7530293aba8b3a2188b89782 Mon Sep 17 00:00:00 2001 From: isidor Date: Wed, 13 Apr 2016 12:17:24 +0200 Subject: [PATCH] debug: better disposing of listeners fixes #5091 --- .../debug/electron-browser/debugService.ts | 27 +++++++++---------- .../parts/debug/node/rawDebugSession.ts | 4 +++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 3d78702c24e9e..82f5334f8d0bc 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -111,6 +111,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService this.model = new model.Model(this.loadBreakpoints(), this.storageService.getBoolean(DEBUG_BREAKPOINTS_ACTIVATED_KEY, StorageScope.WORKSPACE, true), this.loadFunctionBreakpoints(), this.loadExceptionBreakpoints(), this.loadWatchExpressions()); + this.toDispose.push(this.model); this.viewModel = new viewmodel.ViewModel(); this.registerListeners(eventService, lifecycleService); @@ -136,7 +137,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService lifecycleService.onShutdown(this.store, this); lifecycleService.onShutdown(this.dispose, this); - this.windowService.onBroadcast(this.onBroadcast, this); + this.toDispose.push(this.windowService.onBroadcast(this.onBroadcast, this)); } private onBroadcast(broadcast: IBroadcast): void { @@ -231,6 +232,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService } private registerSessionListeners(): void { + this.toDisposeOnSessionEnd.push(this.session); this.toDisposeOnSessionEnd.push(this.session.addListener2(debug.SessionEvents.INITIALIZED, (event: DebugProtocol.InitializedEvent) => { aria.status(nls.localize('debuggingStarted', "Debugging started.")); this.sendAllBreakpoints().then(() => { @@ -710,15 +712,8 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService } private onSessionEnd(): void { - try { - this.debugStringEditorInputs = lifecycle.dispose(this.debugStringEditorInputs); - } catch (e) { - // an internal module might be open so the dispose can throw -> ignore and continue with stop session. - } - if (this.session) { const bpsExist = this.model.getBreakpoints().length > 0; - this.session.dispose(); this.telemetryService.publicLog('debugSessionStop', { type: this.session.getType(), success: this.session.emittedStopped || !bpsExist, @@ -729,7 +724,12 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService } this.session = null; - this.toDisposeOnSessionEnd = lifecycle.dispose(this.toDisposeOnSessionEnd); + try { + this.toDisposeOnSessionEnd = lifecycle.dispose(this.toDisposeOnSessionEnd); + } catch (e) { + // an internal module might be open so the dispose can throw -> ignore and continue with stop session. + } + this.partService.removeClass('debugging'); this.editorService.focusEditor(); @@ -857,6 +857,8 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService if (filtered.length === 0) { const result = this.instantiationService.createInstance(DebugStringEditorInput, source.name, source.uri, source.origin, value, mtype, void 0); this.debugStringEditorInputs.push(result); + this.toDisposeOnSessionEnd.push(result); + return result; } else { return filtered[0]; @@ -933,12 +935,7 @@ export class DebugService extends ee.EventEmitter implements debug.IDebugService } public dispose(): void { - if (this.session) { - this.session.disconnect(); - this.session = null; - } - this.model.dispose(); - this.toDispose = lifecycle.dispose(this.toDispose); this.toDisposeOnSessionEnd = lifecycle.dispose(this.toDisposeOnSessionEnd); + this.toDispose = lifecycle.dispose(this.toDispose); } } diff --git a/src/vs/workbench/parts/debug/node/rawDebugSession.ts b/src/vs/workbench/parts/debug/node/rawDebugSession.ts index 1fad007f08c5e..318efc2b930e4 100644 --- a/src/vs/workbench/parts/debug/node/rawDebugSession.ts +++ b/src/vs/workbench/parts/debug/node/rawDebugSession.ts @@ -340,4 +340,8 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes } this.emit(debug.SessionEvents.SERVER_EXIT); } + + public dispose(): void { + this.disconnect().done(null, errors.onUnexpectedError); + } }