object_pool 1.0.0
object_pool: ^1.0.0 copied to clipboard
A high-performance generic object pool for Dart and Flutter that reduces garbage collection pressure by reusing pre-allocated objects, ideal for games, animations, particle systems, and performance-cr [...]
Changelog #
All notable changes to object_pool are documented here.
Format: Keep a Changelog Versioning: Semantic Versioning
1.0.0 — 2026-05-29 #
Initial stable release.
Added #
Core:
ObjectPool<T>— generic object pool with O(1) acquire/release via an embedded free-list data structure.Poolable— optionalabstract interface classfor objects that participate in pool lifecycle (onAcquire,onRelease,isValid).PoolMetrics— immutable snapshot of pool performance statistics (utilizationRate,hitRate,acquiresPerSecond,leakEstimate, etc.).
Overflow Strategies:
PoolOverflowStrategy<T>— abstract interface for custom strategies.ExpandStrategy— grows the pool when exhausted; respectsmaxSizeand supportsgrowthIncrementfor bulk expansion.DiscardStrategy— returnsnullsilently when exhausted; pool size never grows.ReplaceStrategy— forcibly reclaims the oldest in-use object when exhausted; never returnsnullfor non-empty pools.
API Methods:
acquire()→T?— O(1) acquire; returns null if exhausted and strategy cannot provide.acquireOrThrow()→T— acquire or throwPoolExhaustedException.release(T)— O(1) release with double-release and foreign-object detection.releaseIfNotNull(T?)— convenience null-safe release.use<R>(R Function(T))— RAII-style scoped acquire/release (sync).useAsync<R>(Future<R> Function(T))— RAII-style scoped acquire/release (async). Guaranteed release even when the Future throws.prewarm(int)— ensure at least N objects are ready (no-op if already large).drain()— remove all idle objects to reclaim memory.dispose()— destroy the pool; callsonReleaseon any in-use Poolable objects.
Exceptions:
PoolExhaustedException— thrown byacquireOrThrow()on exhaustion.PoolInvalidReleaseException— thrown byrelease()on foreign-object or double-release errors.
Test Suite (1,162 lines, 40+ test cases):
object_pool_test.dart— initialization, acquire, release, Poolable lifecycle,use()/useAsync(),prewarm()/drain()/dispose(), metrics, edge cases.strategies_test.dart— ExpandStrategy, DiscardStrategy, ReplaceStrategy behaviour including growth limits, no-growth invariants, and forced reclaim.pool_metrics_test.dart— all derived metric properties.concurrency_test.dart— async interleaving, concurrent exhaustion with both ExpandStrategy and DiscardStrategy, exception safety.
Examples:
example/main.dart— five self-contained examples (basic, scoped, overflow strategies, prewarm/drain, metrics dashboard).example/particle_system_example.dart— full 120-frame particle simulation with radial emission, physics, lifecycle, and pool metrics.example/connection_pool_example.dart— database connection pool withvalidateOnAcquire, async queries, concurrent batch execution, and health-check simulation.
Benchmarks:
benchmark/pool_vs_new_benchmark.dart— four micro-benchmarks usingbenchmark_harness: direct allocation, pool acquire/release, pooluse(), and high-frequency 100-particle-per-frame cycling.benchmark/gc_pressure_benchmark.dart— macro-benchmark comparing wall-clock time of a 300-frame game loop with and without pooling, demonstrating cumulative GC pressure elimination.
Documentation:
doc/getting_started.md— step-by-step guide for new users.- Comprehensive
///dartdoc comments on every public symbol. README.mdwith API table, use-case examples, common mistakes, internal architecture diagram, and performance expectations.