Skip to content

ObjectPool

Inherits: Class

Methods

Acquire

lua
function ObjectPool:Acquire()
  -> <T>, boolean

Acquires an object from the pool, creating one if necessary.

Returns:

NameTypeDescription
``<T>
isNewboolean

EnumerateActive

lua
function ObjectPool:EnumerateActive()
  -> fun():T

Returns an iterator over all currently active objects in the pool.

Returns:

TypeDescription
fun():T

EnumerateInactive

lua
function ObjectPool:EnumerateInactive()
  -> fun():T

Returns an iterator over all currently inactive objects in the pool.

Returns:

TypeDescription
fun():T

Get

lua
function ObjectPool:Get()
  -> <T>

Either returns a recycled instance of the object or creates a new one as applicable.

Returns:

TypeDescription
<T>

GetNumActive

lua
function ObjectPool:GetNumActive()
  -> number

Returns the number of currently active objects in the pool.

Returns:

TypeDescription
number

Recycle

lua
function ObjectPool:Recycle(obj)

Recycles an instance of the object back into the pool.

Parameters:

NameTypeDescription
objTThe object to recycle

Release

lua
function ObjectPool:Release(obj)

Releases the given object back into the pool.

Parameters:

NameTypeDescription
objT

ReleaseAll

lua
function ObjectPool:ReleaseAll()

Releases all active objects back into the pool.

_GetDebugInfo

lua
function ObjectPool:_GetDebugInfo()

__init

lua
function ObjectPool:__init(createFunc, extraStackOffset)

Parameters:

NameTypeDescription
createFunc``
extraStackOffset``

Functions

EnableLeakDebug

lua
function ObjectPool.EnableLeakDebug()

Enables leak debugging.

GetDebugInfo

lua
function ObjectPool.GetDebugInfo()
  -> table<string, ObjectPoolDebugInfo>

Gets debug information which represents the current state of all the created object pools

Returns:

TypeDescription
table<string, ObjectPoolDebugInfo>

New

lua
function ObjectPool.New(name, createFunc, extraStackOffset)
  -> ObjectPool

Create a new object pool.

Parameters:

NameTypeDescription
namestringThe name of the object pool for debug purposes
createFuncfun(): T | TThe function which is called to create a new object, or a Class
extraStackOffsetnumberThe extra stack offset for tracking where objects are being used from or nil to disable stack info

Returns:

TypeDescription
ObjectPool