Disposer class

Tracks disposables that are added to it for later disposal.

Example usage: final disposer = new Disposer() ..addDisposable(() => print('Clean up');) ..addDisposable(stream.listen()) ..addDisposable(myCustomDisposable);

disposer.dispose();

Example usage of 'oneShot' mode. Please use this for cases where there is a single call to dispose as it will help detect potential memory leaks where a disposable is being added after the disposer has been disposed. This is very typical for Angular components where disposer.dispose() is called in ngOnDestroy.

final disposer = new Disposer.oneShot()
  ..addDisposable(() => print('Clean up');)
  ..addDisposable(stream.listen());

disposer.dispose();
// The following call will assert.
disposer.addDisposable(myCustomDisposable);

Prefer typed functions whenever possible: addEventSink addFunction addStreamSubscription

Note that you should not rely on the disposal sequence for each added disposable, just treat it random.

Implemented types

Constructors

Disposer.multi()
Convenience constructor for supporting multiple calls to dispose.
Disposer.oneShot()
Pass oneShot as true if no disposables are meant to be added after the dispose method is called. Convenience constructor for one shot mode or single dispose mode.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addDisposable<T>(T disposable) → T
Registers disposable for disposal when dispose is called later.
addEventSink<T>(EventSink<T> disposable) EventSink<T>
Registers disposable.
addFunction(DisposeFunction disposable) DisposeFunction
Registers disposable.
addStreamSubscription<T>(StreamSubscription<T> disposable) StreamSubscription<T>
Registers disposable.
dispose() → void
Disposes this disposable and any resources it has open.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited