structs.SimplePool Extends goog.Disposable
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 actually allocates an array to clean the object passed to it, so simply using this function would defy the purpose of using the pool.

Inheritance

Constructor

goog.structs.SimplePool(initialCountmaxCount)

Parameters

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.

Instance Methods

Public Protected Private
createInitial_(initialCount)
Populates the pool with initialCount objects.
Arguments:
initialCount : number
The number of objects to add to the pool.
code »
createObject() T
Should be overridden by sub-classes to return an instance of the object type that is expected in the pool.
Returns: T  The created object.
code »
disposeInternal()
Disposes of the pool and all objects currently held in the pool.
code »
disposeObject(obj)
Should be overrideen 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.
Arguments:
obj : T
The object to dispose.
code »
getObject() T
Gets an unused object from the the pool, if there is one available, otherwise creates a new one.
Returns: T  An object from the pool or a new one if necessary.
code »
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.
Arguments:
obj : T
The object to release.
code »
setCreateObjectFn(createObjectFn)
Sets the createObject function which is used for creating a new object in the pool.
Arguments:
createObjectFn : Function
Create object function which returns the newly created object.
code »
setDisposeObjectFn(disposeObjectFn)
Sets the disposeObject function which is used for disposing of an object in the pool.
Arguments:
disposeObjectFn : Function
Dispose object function which takes the object to dispose as a parameter.
code »
addOnDisposeCallback(callbackopt_scope)
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
Arguments:
callback : function(this:T):?
The callback function.
opt_scope : T=
An optional scope to call the callback in.
code »
dispose() void
Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: void  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' disposeInternal method. Everywhere else the public dispose method must be used. For example:
  mypackage.MyClass = function() {
    mypackage.MyClass.base(this, 'constructor');
    // Constructor logic specific to MyClass.
    ...
  };
  goog.inherits(mypackage.MyClass, goog.Disposable);

  mypackage.MyClass.prototype.disposeInternal = function() {
    // Dispose logic specific to MyClass.
    ...
    // Call superclass's disposeInternal at the end of the subclass's, like
    // in C++, to avoid hard-to-catch issues.
    mypackage.MyClass.base(this, 'disposeInternal');
  };
code »
getDisposed() boolean
Use #isDisposed instead. No description.
Returns: boolean  Whether the object has been disposed of.
code »
isDisposed() boolean
No description.
Returns: boolean  Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable : goog.disposable.IDisposable
that will be disposed when this object is disposed.
code »

Instance Properties

constructor :
No description.
Code »
createObjectFn_ :
Function for overriding createObject. The avoids a common case requiring subclassing this class.
Code »
disposeObjectFn_ :
Function for overriding disposeObject. The avoids a common case requiring subclassing this class.
Code »
freeQueue_ :
Queue used to store objects that are currently in the pool and available to be used.
Code »
maxCount_ :
Maximum number of objects allowed
Code »
creationStack :
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Code »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
Callbacks to invoke when this object is disposed.
Code »

Static Properties

goog.structs.SimplePool.superClass_ :
No description.
Code »

Package structs

Package Reference