Object pools are a memory management pattern that reduces garbage collection pressure by reusing object instances instead of allocating and discarding them. When an object is needed, it's pulled from a pool's free list; when done, it's returned rather than discarded. This keeps the GC from collecting short-lived objects, which can cause framerate hitches in scenarios like 3D rendering. A JavaScript implementation using an Array as a stack demonstrates alloc() and free() methods. Key caveats: modern GCs are already very good, so pools can hurt performance if misused, and objects should be zeroed out when returned to prevent data leakage.

6m read timeFrom beej.us
Post cover image
Table of contents
ImplementationMisc NotesCode

Sort: