Represents a pool that manages a set of reusable objects.

Type Parameters

  • T

Constructors

Methods

Constructors

  • Creates an instance of ObjectPool.

    Type Parameters

    • T

    Parameters

    • factory: () => T

      A function used to create a new object when the pool is empty.

    • destroy: (obj: T) => void

      A function used to destroy objects when clearing the pool.

    Returns ObjectPool<T>

Methods

  • Acquires an object from the pool or creates a new one if the pool is empty.

    Returns T

    An object from the pool or a new one if the pool is empty.

  • Releases an object back into the pool for reuse.

    Parameters

    • obj: T

      The object to be released into the pool.

    Returns void