dispose and clear things out when they are not needed to free up memory (#5805)

This commit is contained in:
Anthony Dresser
2019-05-31 17:24:01 -07:00
committed by Karl Burtram
parent ba58b0f429
commit 23e4a30cd1
4 changed files with 19 additions and 34 deletions

View File

@@ -77,7 +77,7 @@ export class MessagePanel extends Disposable {
private styleElement = createStyleSheet(this.container); private styleElement = createStyleSheet(this.container);
private queryRunnerDisposables: IDisposable[] = []; private queryRunnerDisposables: IDisposable[] = [];
private _state: MessagePanelState; private _state: MessagePanelState | undefined;
private tree: ITree; private tree: ITree;
@@ -201,7 +201,7 @@ export class MessagePanel extends Disposable {
} }
// convert to old VS Code tree interface with expandable methods // convert to old VS Code tree interface with expandable methods
let expandableTree: IExpandableTree = <IExpandableTree>this.tree; let expandableTree: IExpandableTree = <IExpandableTree>this.tree;
if (this.state.scrollPosition) { if (this.state && this.state.scrollPosition) {
const previousScroll = this.state.scrollPosition; const previousScroll = this.state.scrollPosition;
this.tree.refresh(this.model).then(() => { this.tree.refresh(this.model).then(() => {
// Restore the previous scroll position when switching between tabs // Restore the previous scroll position when switching between tabs
@@ -233,6 +233,7 @@ export class MessagePanel extends Disposable {
private reset() { private reset() {
this.model.messages = []; this.model.messages = [];
this._state = undefined;
this.model.totalExecuteMessage = undefined; this.model.totalExecuteMessage = undefined;
this.tree.refresh(this.model); this.tree.refresh(this.model);
} }

View File

@@ -24,7 +24,6 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
class MessagesView extends Disposable implements IPanelView { class MessagesView extends Disposable implements IPanelView {
private messagePanel: MessagePanel; private messagePanel: MessagePanel;
private container = document.createElement('div'); private container = document.createElement('div');
private _state: MessagePanelState;
constructor(private instantiationService: IInstantiationService) { constructor(private instantiationService: IInstantiationService) {
super(); super();
@@ -59,19 +58,13 @@ class MessagesView extends Disposable implements IPanelView {
} }
public set state(val: MessagePanelState) { public set state(val: MessagePanelState) {
this._state = val;
this.messagePanel.state = val; this.messagePanel.state = val;
} }
public get state(): MessagePanelState {
return this._state;
}
} }
class ResultsView extends Disposable implements IPanelView { class ResultsView extends Disposable implements IPanelView {
private gridPanel: GridPanel; private gridPanel: GridPanel;
private container = document.createElement('div'); private container = document.createElement('div');
private _state: GridPanelState;
constructor(private instantiationService: IInstantiationService) { constructor(private instantiationService: IInstantiationService) {
super(); super();
@@ -106,13 +99,8 @@ class ResultsView extends Disposable implements IPanelView {
} }
public set state(val: GridPanelState) { public set state(val: GridPanelState) {
this._state = val;
this.gridPanel.state = val; this.gridPanel.state = val;
} }
public get state(): GridPanelState {
return this._state;
}
} }
class ResultsTab implements IPanelTab { class ResultsTab implements IPanelTab {

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls'; 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 { Event, Emitter } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
@@ -42,13 +42,13 @@ export interface IQueryEditorStateChange {
connectingChange?: boolean; connectingChange?: boolean;
} }
export class QueryEditorState { export class QueryEditorState extends Disposable {
private _connected = false; private _connected = false;
private _resultsVisible = false; private _resultsVisible = false;
private _executing = false; private _executing = false;
private _connecting = false; private _connecting = false;
private _onChange = new Emitter<IQueryEditorStateChange>(); private _onChange = this._register(new Emitter<IQueryEditorStateChange>());
public onChange = this._onChange.event; public onChange = this._onChange.event;
public set connected(val: boolean) { 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 ID: string = 'workbench.editorinputs.queryInput';
public static SCHEMA: string = 'sql'; public static SCHEMA: string = 'sql';
private _state = new QueryEditorState(); private _state = this._register(new QueryEditorState());
public get state(): QueryEditorState { return this._state; } public get state(): QueryEditorState { return this._state; }
private _updateSelection: Emitter<ISelectionData>; private _updateSelection: Emitter<ISelectionData>;
@@ -122,16 +122,18 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
super(); super();
this._updateSelection = new Emitter<ISelectionData>(); this._updateSelection = new Emitter<ISelectionData>();
this._toDispose = []; this._register(this._sql);
this._register(this._results);
// re-emit sql editor events through this editor if it exists // re-emit sql editor events through this editor if it exists
if (this._sql) { if (this._sql) {
this._toDispose.push(this._sql.onDidChangeDirty(() => this._onDidChangeDirty.fire())); this._register(this._sql.onDidChangeDirty(() => this._onDidChangeDirty.fire()));
} }
// Attach to event callbacks // Attach to event callbacks
if (this._queryModelService) { if (this._queryModelService) {
// Register callbacks for the Actions // Register callbacks for the Actions
this._toDispose.push( this._register(
this._queryModelService.onRunQueryStart(uri => { this._queryModelService.onRunQueryStart(uri => {
if (this.uri === uri) { if (this.uri === uri) {
this.onRunQuery(); this.onRunQuery();
@@ -139,7 +141,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
}) })
); );
this._toDispose.push( this._register(
this._queryModelService.onRunQueryComplete(uri => { this._queryModelService.onRunQueryComplete(uri => {
if (this.uri === uri) { if (this.uri === uri) {
this.onQueryComplete(); this.onQueryComplete();
@@ -149,7 +151,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
} }
if (this._connectionManagementService) { if (this._connectionManagementService) {
this._toDispose.push(this._connectionManagementService.onDisconnect(result => { this._register(this._connectionManagementService.onDisconnect(result => {
if (result.connectionUri === this.uri) { if (result.connectionUri === this.uri) {
this.onDisconnect(); this.onDisconnect();
} }
@@ -164,7 +166,7 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
} }
if (this._configurationService) { if (this._configurationService) {
this._toDispose.push(this._configurationService.onDidChangeConfiguration(e => { this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectedKeys.includes('sql.showConnectionInfoInTitle')) { if (e.affectedKeys.includes('sql.showConnectionInfoInTitle')) {
this._onDidChangeLabel.fire(); this._onDidChangeLabel.fire();
} }
@@ -307,20 +309,13 @@ export class QueryInput extends EditorInput implements IEncodingSupport, IConnec
this.state.executing = false; 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 { public close(): void {
this._queryModelService.disposeQuery(this.uri); this._queryModelService.disposeQuery(this.uri);
this._connectionManagementService.disconnectEditor(this, true); this._connectionManagementService.disconnectEditor(this, true);
this._sql.close(); this._sql.close();
this._results.close(); this._results.close();
super.close();
} }
/** /**

View File

@@ -123,7 +123,7 @@ export class GridPanel {
private runner: QueryRunner; private runner: QueryRunner;
private maximizedGrid: GridTable<any>; private maximizedGrid: GridTable<any>;
private _state: GridPanelState; private _state: GridPanelState | undefined;
constructor( constructor(
@IConfigurationService private readonly configurationService: IConfigurationService, @IConfigurationService private readonly configurationService: IConfigurationService,
@@ -301,6 +301,7 @@ export class GridPanel {
for (let i = this.splitView.length - 1; i >= 0; i--) { for (let i = this.splitView.length - 1; i >= 0; i--) {
this.splitView.removeView(i); this.splitView.removeView(i);
} }
this._state = undefined;
dispose(this.tables); dispose(this.tables);
dispose(this.tableDisposable); dispose(this.tableDisposable);
this.tableDisposable = []; this.tableDisposable = [];
@@ -346,7 +347,7 @@ export class GridPanel {
}); });
} }
public get state(): GridPanelState { public get state() {
return this._state; return this._state;
} }