Interface for objects that can be disposed.
Implementing classes should clean up resources in the dispose method. The disposal process should be idempotent and safe to call multiple times.
Contract:
- dispose must be idempotent (safe to call multiple times)
- After disposal, the object should be in a clean, unusable state
- Resources should be properly released to prevent memory leaks
Example:
class MyResource implements Disposable {
Timer? _timer;
MyResource() {
_timer = Timer.periodic(Duration(seconds: 1), (_) {});
}
@override
Future<void> dispose() async {
_timer?.cancel();
_timer = null;
}
}
- Implementers
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
-
dispose(
) → FutureOr< void> - Dispose this object and clean up its resources.
-
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