Can we store all the disposables in a top-level array or set? #1195
-
I saw lots of extensions managing disposables by storing them in class member and dispose them in the class's Or append disposables to I am wondering why not keep a top-level array or set for disposables and dispose all of them in the export const disposables: vscode.Disposable[] = []
class SomeView{
initialize() {
disposables.push(vscode.window.onXXX)
}
}
export function activate() {
new SomeView()
}
export function deactivate() {
disposables.map(d => d.dispose)
} This will be much simpler, because we don't have to make |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That is a simplified solution to the problem that is not optimal. You should dispose objects as soon as you no longer need them (for example your view is no longer visible). |
Beta Was this translation helpful? Give feedback.
That is a simplified solution to the problem that is not optimal. You should dispose objects as soon as you no longer need them (for example your view is no longer visible).
Your proposed solution - you would only dispose once VS Code is getting shut down (your extension is getting deactivated). This is not optimal and I highly recommend that you dispose your objects as soon as you no longer need them. Thanks