A generic object pool for reusing objects.

Constructor

@:value({ size : null, clean : null, create : null })new(?create:() ‑> T, ?clean:T ‑> Void, ?size:Int)

Creates a new ObjectPool instance.

Parameters:

create

A function that creates a new instance of type T.

clean

A function that cleans up an instance of type T before it is reused.

size

The maximum size of the object pool.

Variables

read onlyactiveObjects:Int

The number of active objects in the pool.

read onlyinactiveObjects:Int

The number of inactive objects in the pool.

size:Null<Int>

The total size of the object pool (both active and inactive objects).

Methods

add(object:T):Void

Adds an object to the object pool.

Parameters:

object

The object to add to the pool.

dynamicclean(object:T):Void

Dynamic function.

Cleans up an object before returning it to the pool.

Parameters:

object

The object to clean up.

clear():Void

Clears the object pool, removing all objects.

dynamiccreate():T

Dynamic function.

Creates a new Object.

get():T

Creates a new object and adds it to the pool, or returns an existing inactive object from the pool.

Returns:

The object retrieved from the pool, or null if the pool is full and no new objects can be created.

release(object:T):Void

Releases an active object back into the pool.

Parameters:

object

The object to release.

remove(object:T):Void

Removes an object from the pool.

Parameters:

object

The object to remove from the pool.