MemoryScope class

Groups cleanup steps that share one lifetime (a scene, a subsystem) and runs them together, last registered first.

final scene = MemoryScope(debugLabel: 'battle');
final bullet = bulletPool.acquireScoped(scene);
await textures.acquire('boss.png', scope: scene);
scene.own(() => print('battle torn down'));
// ...
await scene.disposeAsync();

Every own call adds one callback that lives until the scope is disposed, so give long-lived scopes long-lived things and use a child scope for anything acquired per frame or per wave.

Constructors

MemoryScope({String? debugLabel})
Creates an empty scope.

Properties

debugLabel → String?
A name used in error messages.
final
hashCode → int
The hash code for this object.
no setterinherited
isDisposed → bool
Whether dispose or disposeAsync has run.
no setter
ownedCount → int
How many cleanup callbacks are waiting.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

child({String? debugLabel}) → MemoryScope
Creates a scope that is disposed with this one (or earlier, on its own).
dispose() → void
Runs every callback, last registered first, without waiting for asynchronous ones.
disposeAsync() → Future<void>
Runs every callback, last registered first, waiting for each one.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
own(DisposeCallback callback) → void
Registers callback to run when the scope is disposed. On a scope that is already disposed, callback runs at once (its future, if any, is not awaited).
ownValue<T>(T value, void disposer(T value)) → T
Registers disposer to run on value when the scope is disposed, and returns value.
toString() → String
A string representation of this object.
inherited

Operators

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