Release the resource. Resolves once the player confirmed the release (or immediately for purely local resources). Never rejects.
A "Turn feature off" item removes the feature's own menu item at once,
before the plugin stops. dispose takes the command out of the menu and
the binding table and resolves once the player confirmed it; the id can
be added again later.
const extra = plugin.commands.add({ id: "extra", path: ["Tools", "Extra"], run() {} });
plugin.commands.add({
id: "extra-off",
path: ["Tools", "Turn extra off"],
run: () => extra.dispose(), // never rejects
});
Anything that owns player-side or local resources: every handle the API returns (commands, windows, panels, filters, snapshots, listeners…).
A handle belongs to the Scope that created it and is disposed with that scope, so most plugins never call
dispose()themselves. Call it to release one resource early. Disposing twice is harmless, anddispose()never rejects: failures are only written to the plugin log.What disposal does depends on the handle: a Command leaves the menu and the binding table, a Window closes, a Panel is unmounted, a VideoFilter / AudioFilter withdraws this plugin's chain, a Snapshot is released, an unfinished ExportJob is cancelled, a Stream stops, a Resolver is unregistered (aborting resolutions in flight), a JsonStore flushes, a running
tools.runprocess is killed and a listener is unsubscribed. A Media is the exception: disposing its scope does not close the media; call Media.close for that.Example: Stop listening once the file is ready
The listener reacts to the first time the source becomes ready and then stops being called. Every registration returns a
Disposable; disposing it removes just that listener, before the scope that owns it ends.Remarks
Every handle a plugin creates is a
Disposableowned by the scope that created it; disposing the scope (or stopping the plugin) disposes them in reverse creation order, so a plugin rarely callsdisposeitself.Since
1.0.0