ObjectPool<T> class
Generic acquire/release object pool (FEAT-48) — reuses instances of T
(a Flame particle/projectile component, or any other allocation-heavy
object) instead of letting a hot gameplay loop allocate and immediately
discard one every frame.
Identity, not equality, decides which object is "active": release
checks that the exact instance passed in is the one this pool currently
considers acquired, so a subclass of T overriding ==/hashCode
doesn't confuse double-release detection.
Constructors
- ObjectPool({required T create(), void reset(T item)?, void dispose(T item)?, int maxCapacity = 200})
Properties
- activeCount → int
-
no setter
- freeCount → int
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxCapacity → int
-
Upper bound on
freeCount + activeCountthis pool ever holds onto — acquire may still create past it (a pool never refuses to hand out an object), but release disposes rather than retains once at the cap, so a burst that briefly exceeds it doesn't permanently bloat the pool's resting size.final - peakActive → int
-
Highest activeCount this pool has ever reached.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- totalCreated → int
-
Total number of objects
createhas ever produced — the metric a benchmark compares against an unpooled baseline to show reuse working.no setter
Methods
-
acquire(
) → T -
Hands out a reusable
T— an existing free one if available, otherwise a freshlycreated one. Always succeeds; maxCapacity bounds what release retains, not what acquire can hand out. -
disposeAll(
) → void - Disposes every object this pool currently holds — free and active alike — and empties it. For tearing the pool down entirely (e.g. a game session ending), not for routine reuse.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
prewarm(
int count) → void -
Creates up to
countobjects ahead of time into the free list, so the first burst of real acquire calls doesn't pay allocation cost. Capped at maxCapacity — never over-fills the pool's resting size. -
release(
T item) → void -
Returns
itemto the pool —resetclears its mutable gameplay state, then it either rejoins the free list or, iffreeCount + activeCountis already at maxCapacity, isdisposed instead of retained. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited