A generic object pool for reusing objects.
Constructor
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
Methods
dynamicclean(object:T):Void
Dynamic function.
Cleans up an object before returning it to the pool.
Parameters:
object | The object to clean up. |
---|
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. |
---|