| name | jobjectpool |
| description | JObjectPool thread-safe object pooling for Unity. Triggers on: object pool, GC optimization, reusable instances, bullet pool, enemy pool, effect pool, spawn pool, reduce garbage collection, memory optimization, pool prewarm, Rent Return pattern, lock-free pool |
JObjectPool - Thread-Safe Object Pooling
Thread-safe, lock-free generic object pooling for Unity using CAS operations. Works with job system and async operations.
When to Use
- Frequently instantiated objects (bullets, enemies, effects)
- Reducing GC during gameplay
- Multi-threaded object reuse (safe from any thread)
- High-frequency object lifecycle operations
Core API
Constructor
new JObjectPool<T>(
int maxSize = 64,
Action<T> onRent = null,
Action<T> onReturn = null
)
Note: T must be a reference type with a parameterless constructor (where T : class, new()).
Methods
.Rent() - Get object from pool or create new
.Return(T obj) - Return object to pool (null values ignored)
.Clear() - Remove all pooled objects
.Prewarm(int count) - Pre-allocate objects (won't exceed maxSize)
.Count - Current available count (approximate, thread-safe)