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 (ExpandoFinalizer) 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

Constructors

ExpandoWithFinalizer(ExpandoFinalizer<V> onFinalize)

Properties

hashCode int
The hash code for this object.
no setterinherited
onFinalize ExpandoFinalizer<V>
User-provided finalization callback.
final
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.
get(K key) → V?
Returns associated value if the key is still alive.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(K key, V value) → void
Associates value with key, replacing any previous value. Cancels the previous finalization and attaches a new one. When the key is GC-collected, onFinalize is called with the value.
remove(K key) → V?
Removes and returns the value associated with key, if any. Cancels the pending finalization for that association.
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 value with key. See put.