View Source on Github

Object Pool

Difficulty-Beginner Java Performance Creational


When objects are expensive to create and they are needed only for short periods of time it is advantageous to utilize the Object Pool pattern. The Object Pool provides a cache for instantiated objects tracking which ones are in use and which are available.

alt text


Use the Object Pool pattern when

  • the objects are expensive to create (allocation cost)
  • you need a large number of short-lived objects (memory fragmentation)