The goog.structs.SimplePool Class

goog.structs.SimplePool
> goog.Disposable

goog.structs.SimplePool(initialCount, maxCount)

A generic pool class. Simpler and more efficient than goog.structs.Pool because it doesn't maintain a list of objects that are in use. This class has constant overhead and doesn't create any additional objects as part of the pool management after construction time. IMPORTANT: If the objects being pooled are arrays or maps that can have unlimited number of properties, they need to be cleaned before being returned to the pool. Also note that {@see goog.object.clean} actually allocates an array to clean the object passed to it, so simply using this function would defy the purpose of using the pool.

initialCount {number}
Initial number of objects to populate the free pool at construction time.
maxCount {number}
Maximum number of objects to keep in the free pool.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.createObject()

Should be overriden by sub-classes to return an instance of the object type that is expected in the pool.

returns {*}
The created object.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.disposeObject(obj)

Should be overriden to dispose of an object. Default implementation is to remove all of the object's members, which should render it useless. Calls the object's dispose method, if available.

obj {*}
The object to dispose.

.getObject()

Gets an unused object from the the pool, if there is one available, otherwise creates a new one.

returns {*}
An object from the pool or a new one if necessary.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.releaseObject(obj)

Returns an object to the pool so that it can be reused. If the pool is already full, the object is disposed instead.

obj {*}
The object to release.

.setCreateObjectFn(createObjectFn)

Sets the {@code createObject} function which is used for creating a new object in the pool.

createObjectFn {Function}
Create object function which returns the newly createrd object.

.setDisposeObjectFn(disposeObjectFn)

Sets the {@code disposeObject} function which is used for disposing of an object in the pool.

disposeObjectFn {Function}
Dispose object function which takes the object to dispose as a parameter.