⁘ common.pool

DisposableObject

This is the base class for most of the objects in the @nkmjs ecosystem.
They encapsulate boilerplate code that allow the common.pool.POOL to function correctly and streamline pooled object behavior. If you are coming from any other programming language that supports interfaces, see this as an IDisposable, with all the boilerplate code already implemented.
If you need to broadcast signals, consider using common.pool.DisposableObjectEx instead.

go to → Members
Initialization

Methods

protectedoverride-me_Init()

Called only once in the constructor of the object, _Init, well, initialize the object.
Use it for initlizing variables, members, bind functions etc, so they can be used safely in _PostInit.
Note : There is no need to call super() on this member when immediately extending DisposableObject, the function is a stub.

protectedoverride-me_PostInit()

Called only once in the constructor of the object, right after _Init. This allows your constructor to perform operations on members etc, knowing they have been properly initilized with their default or intended values.
Note : There is no need to call super() on this member when immediately extending DisposableObject, the function is a stub.

Utils

Methods

protected_Bind(p_func)

Bind the given function to this object and returns it. Note that it replaces the function reference, hence referencing function before they are being bound in _Init, ( i.e in the constructor ) will target an obsolete function.

Parameters:
Name Type Description
p_func *
Pooling

Group of methods related to the NKMjs pooling system.

Members

read-onlyisReleasing :boolean

Whether the object is currently in the process of being released or not.

Methods

Release()

Releases the object and returns it back to the pool.
If you want to do operations when the object is released, do so by overriding the _CleanUp method.

protectedoverride-me_CleanUp()

Called when the object is released. Resets most properties to their initial values.
Override this method in your own implementations to 'reset' the object to the state you want it to be when it gets rented again through common.POOL.Rent

Examples:
MyClass extends DisposableObject{

    _Init(){
        this._arr = []; // Create member during _Init
    }

    _CleanUp(){ 
        this._arr.length = 0; // Reset member during _CleanUp
    }

}