Skip to content
Techniques & Technology

Object Pooling

Reuse, don't reallocate

Object pooling pre-allocates and reuses game objects instead of creating and destroying them, avoiding memory fragmentation and allocation overhead.

cross-platform programmingmemoryoptimisation 1970–present

Overview

Creating and destroying objects during gameplay causes problems: memory allocation takes time, and frequent allocation/deallocation fragments memory. Object pooling solves this by pre-allocating a fixed number of objects and recycling them. Bullets don’t get created—they’re borrowed from a pool. When finished, they return to the pool rather than being destroyed.

Fast facts

  • Problem solved: allocation overhead and fragmentation.
  • Solution: pre-allocate and recycle objects.
  • Common uses: bullets, particles, enemies.
  • Implementation: array of pre-created objects, active flag.
  • Tradeoff: fixed maximum count, slightly complex management.

How it works

Object pooling pattern:

  1. Initialisation: create pool of objects at startup.
  2. Request: mark object active, return reference.
  3. Use: treat as normal object.
  4. Release: mark inactive, stays in pool.
  5. Reuse: next request uses same object.

When to use

Object pooling benefits:

  • Frequent creation: many short-lived objects.
  • Predictable count: known maximum needed.
  • Performance critical: allocation pauses unacceptable.
  • Constrained memory: fragmentation dangerous.

See also