From 23e4a30cd12e9cb97aad5a64e8262e19ad2878ec Mon Sep 17 00:00:00 2001 From: Anthony Dresser Date: Fri, 31 May 2019 17:24:01 -0700 Subject: [PATCH] dispose and clear things out when they are not needed to free up memory (#5805) --- .../parts/query/browser/messagePanel.ts | 5 +-- .../parts/query/browser/queryResultsView.ts | 12 ------- .../parts/query/common/queryInput.ts | 31 ++++++++----------- .../parts/query/electron-browser/gridPanel.ts | 5 +-- 4 files changed, 19 insertions(+), 34 deletions(-) diff --git a/src/sql/workbench/parts/query/browser/messagePanel.ts b/src/sql/workbench/parts/query/browser/messagePanel.ts index 56bb25f55c..2ff19f126e 100644 --- a/src/sql/workbench/parts/query/browser/messagePanel.ts +++ b/src/sql/workbench/parts/query/browser/messagePanel.ts @@ -77,7 +77,7 @@ export class MessagePanel extends Disposable { private styleElement = createStyleSheet(this.container); private queryRunnerDisposables: IDisposable[] = []; - private _state: MessagePanelState; + private _state: MessagePanelState | undefined; private tree: ITree; @@ -201,7 +201,7 @@ export class MessagePanel extends Disposable { } // convert to old VS Code tree interface with expandable methods let expandableTree: IExpandableTree = this.tree; - if (this.state.scrollPosition) { + if (this.state && this.state.scrollPosition) { const previousScroll = this.state.scrollPosition; this.tree.refresh(this.model).then(() => { // Restore the previous scroll position when switching between tabs @@ -233,6 +233,7 @@ export class MessagePanel extends Disposable { private reset() { this.model.messages = []; + this._state = undefined; this.model.totalExecuteMessage = undefined; this.tree.refresh(this.model); } diff --git a/src/sql/workbench/parts/query/browser/queryResultsView.ts b/src/sql/workbench/parts/query/browser/queryResultsView.ts index 6f2da98ebe..3a6e98d57f 100644 --- a/src/sql/workbench/parts/query/browser/queryResultsView.ts +++ b/src/sql/workbench/parts/query/browser/queryResultsView.ts @@ -24,7 +24,6 @@ import { IThemeService } from 'vs/platform/theme/common/themeService'; class MessagesView extends Disposable implements IPanelView { private messagePanel: MessagePanel; private container = document.createElement('div'); - private _state: MessagePanelState; constructor(private instantiationService: IInstantiationService) { super(); @@ -59,19 +58,13 @@ class MessagesView extends Disposable implements IPanelView { } public set state(val: MessagePanelState) { - this._state = val; this.messagePanel.state = val; } - - public get state(): MessagePanelState { - return this._state; - } } class ResultsView extends Disposable implements IPanelView { private gridPanel: GridPanel; private container = document.createElement('div'); - private _state: GridPanelState; constructor(private instantiationService: IInstantiationService) { super(); @@ -106,13 +99,8 @@ class ResultsView extends Disposable implements IPanelView { } public set state(val: GridPanelState) { - this._state = val; this.gridPanel.state = val; } - - public get state(): GridPanelState { - return this._state; - } } class ResultsTab implements IPanelTab { diff --git a/src/sql/workbench/parts/query/common/queryInput.ts b/src/sql/workbench/parts/query/common/queryInput.ts index 4d9e007fa9..049c8a17f8 100644 --- a/src/sql/workbench/parts/query/common/queryInput.ts +++ b/src/sql/workbench/parts/query/common/queryInput.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { localize } from 'vs/nls'; -import { IDisposable, dispose } from 'vs/base/common/lifecycle'; +import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle'; import { Event, Emitter } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; @@ -42,13 +42,13 @@ export interface IQueryEditorStateChange { connectingChange?: boolean; } -export class QueryEditorState { +export class QueryEditorState extends Disposable { private _connected = false; private _resultsVisible = false; private _executing = false; private _connecting = false; - private _onChange = new Emitter(); + private _onChange = this._register(new Emitter()); public onChange = this._onChange.event; public set connected(val: boolean) { @@ -105,7 +105,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec public static ID: string = 'workbench.editorinputs.queryInput'; public static SCHEMA: string = 'sql'; - private _state = new QueryEditorState(); + private _state = this._register(new QueryEditorState()); public get state(): QueryEditorState { return this._state; } private _updateSelection: Emitter; @@ -122,16 +122,18 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec super(); this._updateSelection = new Emitter(); - this._toDispose = []; + this._register(this._sql); + this._register(this._results); + // re-emit sql editor events through this editor if it exists if (this._sql) { - this._toDispose.push(this._sql.onDidChangeDirty(() => this._onDidChangeDirty.fire())); + this._register(this._sql.onDidChangeDirty(() => this._onDidChangeDirty.fire())); } // Attach to event callbacks if (this._queryModelService) { // Register callbacks for the Actions - this._toDispose.push( + this._register( this._queryModelService.onRunQueryStart(uri => { if (this.uri === uri) { this.onRunQuery(); @@ -139,7 +141,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec }) ); - this._toDispose.push( + this._register( this._queryModelService.onRunQueryComplete(uri => { if (this.uri === uri) { this.onQueryComplete(); @@ -149,7 +151,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec } if (this._connectionManagementService) { - this._toDispose.push(this._connectionManagementService.onDisconnect(result => { + this._register(this._connectionManagementService.onDisconnect(result => { if (result.connectionUri === this.uri) { this.onDisconnect(); } @@ -164,7 +166,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec } if (this._configurationService) { - this._toDispose.push(this._configurationService.onDidChangeConfiguration(e => { + this._register(this._configurationService.onDidChangeConfiguration(e => { if (e.affectedKeys.includes('sql.showConnectionInfoInTitle')) { this._onDidChangeLabel.fire(); } @@ -307,20 +309,13 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec this.state.executing = false; } - // Clean up functions - public dispose(): void { - this._sql.dispose(); - this._results.dispose(); - this._toDispose = dispose(this._toDispose); - super.dispose(); - } - public close(): void { this._queryModelService.disposeQuery(this.uri); this._connectionManagementService.disconnectEditor(this, true); this._sql.close(); this._results.close(); + super.close(); } /** diff --git a/src/sql/workbench/parts/query/electron-browser/gridPanel.ts b/src/sql/workbench/parts/query/electron-browser/gridPanel.ts index d949df64af..a8ee9b89a9 100644 --- a/src/sql/workbench/parts/query/electron-browser/gridPanel.ts +++ b/src/sql/workbench/parts/query/electron-browser/gridPanel.ts @@ -123,7 +123,7 @@ export class GridPanel { private runner: QueryRunner; private maximizedGrid: GridTable; - private _state: GridPanelState; + private _state: GridPanelState | undefined; constructor( @IConfigurationService private readonly configurationService: IConfigurationService, @@ -301,6 +301,7 @@ export class GridPanel { for (let i = this.splitView.length - 1; i >= 0; i--) { this.splitView.removeView(i); } + this._state = undefined; dispose(this.tables); dispose(this.tableDisposable); this.tableDisposable = []; @@ -346,7 +347,7 @@ export class GridPanel { }); } - public get state(): GridPanelState { + public get state() { return this._state; }