Fix terminal object leaking

This commit is contained in:
Daniel Imms
2020-05-03 12:46:37 -07:00
parent 66b2c01549
commit b75e42a56c
10 changed files with 74 additions and 37 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
this._instantiationService.setService(IBufferService, this._bufferService);
this._logService = this._instantiationService.createInstance(LogService);
this._instantiationService.setService(ILogService, this._logService);
this._coreService = this._instantiationService.createInstance(CoreService, () => this.scrollToBottom());
this._coreService = this.register(this._instantiationService.createInstance(CoreService, () => this.scrollToBottom()));
this._instantiationService.setService(ICoreService, this._coreService);
this._coreMouseService = this._instantiationService.createInstance(CoreMouseService);
this._instantiationService.setService(ICoreMouseService, this._coreMouseService);
+3 -1
View File
@@ -28,9 +28,11 @@ export abstract class Disposable implements IDisposable {
/**
* Registers a disposable object.
* @param d The disposable to register.
* @returns The disposable.
*/
public register<T extends IDisposable>(d: T): void {
public register<T extends IDisposable>(d: T): T {
this._disposables.push(d);
return d;
}
/**
+13 -6
View File
@@ -7,6 +7,7 @@ import { ICoreService, ILogService, IOptionsService, IBufferService } from 'comm
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { IDecPrivateModes, IModes } from 'common/Types';
import { clone } from 'common/Clone';
import { Disposable } from 'common/Lifecycle';
const DEFAULT_MODES: IModes = Object.freeze({
insertMode: false
@@ -22,7 +23,7 @@ const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({
wraparound: true // defaults: xterm - true, vt100 - false
});
export class CoreService implements ICoreService {
export class CoreService extends Disposable implements ICoreService {
public serviceBrand: any;
public isCursorInitialized: boolean = false;
@@ -30,20 +31,26 @@ export class CoreService implements ICoreService {
public modes: IModes;
public decPrivateModes: IDecPrivateModes;
private _onData = new EventEmitter<string>();
// Circular dependency, this must be unset or memory will leak after Terminal.dispose
private _scrollToBottom: (() => void) | undefined;
private _onData = this.register(new EventEmitter<string>());
public get onData(): IEvent<string> { return this._onData.event; }
private _onUserInput = new EventEmitter<void>();
private _onUserInput = this.register(new EventEmitter<void>());
public get onUserInput(): IEvent<void> { return this._onUserInput.event; }
private _onBinary = new EventEmitter<string>();
private _onBinary = this.register(new EventEmitter<string>());
public get onBinary(): IEvent<string> { return this._onBinary.event; }
constructor(
// TODO: Move this into a service
private readonly _scrollToBottom: () => void,
scrollToBottom: () => void,
@IBufferService private readonly _bufferService: IBufferService,
@ILogService private readonly _logService: ILogService,
@IOptionsService private readonly _optionsService: IOptionsService
) {
super();
this._scrollToBottom = scrollToBottom;
this.register({ dispose: () => this._scrollToBottom = undefined });
this.modes = clone(DEFAULT_MODES);
this.decPrivateModes = clone(DEFAULT_DEC_PRIVATE_MODES);
}
@@ -62,7 +69,7 @@ export class CoreService implements ICoreService {
// Input is being sent to the terminal, the terminal should focus the prompt.
const buffer = this._bufferService.buffer;
if (buffer.ybase !== buffer.ydisp) {
this._scrollToBottom();
this._scrollToBottom!();
}
// Fire onUserInput so listeners can react as well (eg. clear selection)