DelegatedRefCountHelper<T> class
Helper class for managing reference-counted shared resources.
Tracks how many times a resource is acquired and automatically disposes it when the reference count reaches zero.
Parameters:
- source: The resource to manage
onCreate: Optional callback when helper is created- onDispose: Optional callback when resource is disposed
- autoDispose: Whether to automatically dispose the source (default: true)
Example:
final source = Signal(42);
final helper = DelegatedRefCountHelper<Signal<int>>(
source,
onDispose: (signal) => print('Disposed'),
);
final delegated1 = DelegatedSignal(helper);
final delegated2 = DelegatedSignal(helper);
// Both share the same source
delegated1.dispose();
delegated2.dispose(); // Source is disposed here
Constructors
- DelegatedRefCountHelper(T source, {void onCreate(T source)?, void onDispose(T source)?, bool autoDispose = true})
Properties
- autoDispose → bool
-
final
- count → int
-
Current reference count.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- onDispose ↔ void Function(T source)?
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- source ↔ T
-
latefinal
Methods
-
acquire(
) → T - Increments reference count and returns the source.
-
dispose(
) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
release(
) → bool - Decrements reference count and disposes if count reaches zero.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited