release method
void
release(
- T item
Returns item to the pool — reset clears its mutable gameplay
state, then it either rejoins the free list or, if
freeCount + activeCount is already at maxCapacity, is
disposed instead of retained.
Throws StateError if item isn't currently acquired from this pool
— either a double-release of something already returned, or an object
this pool never handed out.
Implementation
void release(T item) {
if (!_active.remove(item)) {
throw StateError(
'release() called with an object not currently active in this '
'pool — either a double-release or an object this pool never '
'acquired out',
);
}
_reset?.call(item);
if (_free.length + _active.length < maxCapacity) {
_free.add(item);
} else {
_dispose?.call(item);
}
}