ExpandoWithFinalizer<K extends Object, V extends Object> class
A weak key → strong value association similar to Expando, but with a finalization callback.
When a key becomes unreachable and is garbage-collected, the provided
onFinalize (FinalizerCallback) is invoked with the last associated value.
The value remains alive while associated with the key. Replacing or removing the value cancels the pending finalization for the previous association.
Typical use cases:
- Cleaning native resources tied to Dart objects
- Cache entries that must release external handles
- Lifecycle hooks without modifying the key class
- Inheritance
-
- Object
- WithFinalizer<
K, V, ExpandoValueWrapper< V> > - ExpandoWithFinalizer
Constructors
-
ExpandoWithFinalizer(FinalizerCallback<
V> onFinalize, {bool debug = false}) - Creates an ExpandoWithFinalizer.
Properties
- debug → bool
-
Enables debug mode.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
onFinalize
→ FinalizerCallback<
V> -
User-provided callback invoked when a key is garbage-collected.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
containsKey(
K key) → bool -
Returns whether a value is currently associated with
key. -
createWrapper(
K key, V value) → ExpandoValueWrapper< V> -
Creates and stores a wrapper for the given
keyandvalue.override -
get(
K key) → V? -
Returns associated value if the
keyis still alive. -
getWrapper(
K key) → ExpandoValueWrapper< V> ? -
Returns the wrapper associated with
key, if any.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onFinalizeError(
Object error, StackTrace stackTrace) → void -
Called when onFinalize throws.
inherited
-
put(
K key, V value) → void -
Associates
valuewithkey, replacing any existing association.inherited -
remove(
K key) → V? -
Removes the association for
key, if present.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
K key) → V? -
Returns the value associated with
key. See get. -
operator []=(
K key, V value) → void -
Associates
valuewithkey. See put.