# Class: Pool<T>

A pool of objects that can be reused to avoid allocation.

author Nathan Sweet

# Type parameters

Name Type Description
T extends Poolable The type of objects to pool.

# Table of contents

# Constructors

# Methods

# Constructors

# constructor

new Pool<T>(create, max?)

Creates a pool with an initial capacity and a maximum.

# Type parameters

Name Type
T extends Poolable

# Parameters

Name Type Default value Description
create () => T undefined A function to create a new object.
max number Number.MAX_SAFE_INTEGER The maximum number of free objects to store in this pool.

# Defined in

src/pooling/Pool.ts:28 (opens new window)

# Methods

# free

free(object): void

Puts the specified object in the pool, making it eligible to be returned by obtain. If the pool already contains {@link max} free objects, the specified object is not added to the pool. The pool does not check if an object is already freed, so the same object must not be freed multiple times.

# Parameters

Name Type Description
object T The object to free.

# Returns

void

# Defined in

src/pooling/Pool.ts:47 (opens new window)


# obtain

obtain(): T

# Returns

T

An object from this pool. The object may be new or reused (previously freed).

# Defined in

src/pooling/Pool.ts:36 (opens new window)