fix listener leaks (#17913)

* fix listener leaks

* add null check

* simplify

* pr comments
This commit is contained in:
Alan Ren
2021-12-14 13:35:00 -08:00
committed by GitHub
parent 2b1acbc2c7
commit 970fe12e70
7 changed files with 59 additions and 43 deletions

View File

@@ -276,6 +276,7 @@ export class ServerTreeView extends Disposable implements IServerTreeView {
if (profile) {
newProfile = profile;
}
groups.forEach(group => group.dispose());
}
const currentSelections = this._tree!.getSelection();

View File

@@ -480,6 +480,9 @@ export class ConnectionDialogService implements IConnectionDialogService {
this._connectionDialog.onFillinConnectionInputs((input) => this.handleFillInConnectionInputs(input as IConnectionProfile));
this._connectionDialog.onResetConnection(() => this.handleProviderOnResetConnection());
this._connectionDialog.render();
this._connectionDialog.onClosed(() => {
this._model?.dispose();
});
}
this._connectionDialog.newConnectionParams = params;
this._connectionDialog.updateProvider(this._providerNameToDisplayNameMap[this._currentProviderType]);

View File

@@ -8,7 +8,14 @@ import { WorkbenchAsyncDataTree } from 'vs/platform/list/browser/listService';
import { FuzzyScore } from 'vs/base/common/filters';
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { IAsyncDataTreeViewState } from 'vs/base/browser/ui/tree/asyncDataTree';
export class AsyncServerTree extends WorkbenchAsyncDataTree<ConnectionProfileGroup, ServerTreeElement, FuzzyScore> { }
export class AsyncServerTree extends WorkbenchAsyncDataTree<ConnectionProfileGroup, ServerTreeElement, FuzzyScore> {
override async setInput(input: ConnectionProfileGroup, viewState?: IAsyncDataTreeViewState): Promise<void> {
const originalInput = this.getInput();
await super.setInput(input, viewState);
originalInput?.dispose();
}
}
export type ServerTreeElement = ConnectionProfile | ConnectionProfileGroup | TreeNode;

View File

@@ -11,7 +11,7 @@ import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/br
import { NodeType } from 'sql/workbench/services/objectExplorer/common/nodeType';
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
import { Disposable } from 'vs/base/common/lifecycle';
import { Disposable, isDisposable } from 'vs/base/common/lifecycle';
import { onUnexpectedError } from 'vs/base/common/errors';
import { AsyncServerTree, ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
@@ -125,8 +125,12 @@ export class TreeUpdateUtils {
let treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService);
if (treeInput) {
if (treeInput !== tree.getInput()) {
const originalInput = tree.getInput();
if (treeInput !== originalInput) {
return tree.setInput(treeInput).then(async () => {
if (isDisposable(originalInput)) {
originalInput.dispose();
}
// Make sure to expand all folders that where expanded in the previous session
if (targetsToExpand) {
await tree.expandAll(targetsToExpand);