Object Pool Pattern

Learn about the object pool design pattern and how to use it.

Description

The object pool design pattern is a creational design pattern in which a pool of objects is initialized and created beforehand and kept in a pool. As and when needed, a client can request an object from the pool, use it, and return it to the pool. The object in the pool is never destroyed.

When to use

We want to use the object pool pattern in the following scenarios:

  • Avoid high runtime creation cost: Use when the cost to create an instance of a class on the fly is high and the number of such instances that will be needed at a particular time is limited.
    Let’s take ...