Skip to content

Review places where we use IDisposable[] in the code #74250

@mjbvz

Description

@mjbvz

Problem

Our code commonly uses IDisposable[] to track multiple disposables. This is not safe and may leak disposables. Consider:

const disposables: IDisposable[] = [];
disposables.push(new DisposableThing());
dispose(disposables);
disposables.push(new DisposableThing2());

This results in DisposableThing2 being leaked. This sequence of calls can easily happen in async code or in complex sync code

Proposed Fix

Review places where we use IDisposable[]. In almost all cases, we should either:

  • For classes, extend Disposable instead of creating a disposables private property. The Disposable class correctly handles the above case.

  • In place of a IDisposable[], use DisposableStore which was added by Add DisposableStore for use in VS Code #74242 for this very reason.

Metadata

Metadata

Assignees

Labels

debtCode quality issues

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions