Introduce DisposableStore

Fixes #74242

Our current usage of dispoable arrays can leak disposables (see #74242 for details). This change introduces a new class called `DisposableStore` that can be used mostly as a drop in replacement for an array of disposables but will not leak disposbles if it is disposed

`DisposableStore` was extracted from the existing `Dispoable` class, which already implements this pattern. However `Disposable` is intended to be used as a base class while `DispoableStore` is a value class.

In addition, this change hides the `toDispose` / `_toDipose` members of `Disposable` as direct write access to the disposable array also allows for leaks (and breaks encapsulation)
This commit is contained in:
Matt Bierner
2019-05-23 19:25:16 -07:00
parent ae8da480f0
commit 3d5ce6be5e
14 changed files with 73 additions and 64 deletions

View File

@@ -64,12 +64,12 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
super();
this._proxy = context.getProxy(ExtHostContext.ExtHostWebviews);
_editorService.onDidActiveEditorChange(this.onActiveEditorChanged, this, this._toDispose);
_editorService.onDidVisibleEditorsChange(this.onVisibleEditorsChanged, this, this._toDispose);
this._register(_editorService.onDidActiveEditorChange(this.onActiveEditorChanged, this));
this._register(_editorService.onDidVisibleEditorsChange(this.onVisibleEditorsChanged, this));
// This reviver's only job is to activate webview extensions
// This should trigger the real reviver to be registered from the extension host side.
this._toDispose.push(_webviewService.registerReviver({
this._register(_webviewService.registerReviver({
canRevive: (webview) => {
const viewType = webview.state.viewType;
if (viewType) {
@@ -80,9 +80,9 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
reviveWebview: () => { throw new Error('not implemented'); }
}));
lifecycleService.onBeforeShutdown(e => {
this._register(lifecycleService.onBeforeShutdown(e => {
e.veto(this._onBeforeShutdown());
}, this, this._toDispose);
}, this));
}
public $createWebviewPanel(