Register a disposable resource. Accepts:
dispose() method) — e.g. from onEventList.on())null or undefined (safe no-op for conditional subscriptions)When dispose is called, all registered resources are cleaned up.
The resource to register for disposal
const store = new DisposableStore();
// IDisposable object from on()
store.add(on(window, "resize", handler));
// Function returned by EventList.on()
store.add(myEvent.on(handler));
// Raw cleanup function
store.add(() => connection.close());
// Conditional — safe with undefined
store.add(this.maybeEvent?.on(handler));
Dispose all registered resources. Each registered disposable is cleaned up, then the internal list is cleared. The store can be reused after disposal.
Called automatically by the engine when a component's onDisable lifecycle fires.
A store for managing disposable resources (event subscriptions, listeners, callbacks) that should be cleaned up together.
DisposableStore collects disposables and disposes them all at once when dispose is called. After disposal, the store can be reused — new items can be added and a subsequent dispose call will clean those up.
This is the same pattern used internally by VSCode for lifecycle-bound resource management.
Example: Basic usage
Example: Use with Needle Engine components