class sap.ui.base.ObjectPool

Control sample: sap.ui.base.ObjectPool
Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/base/ObjectPool
Application Component: CA-UI5-COR

Manages a pool of objects for reuse, all of the same type; the type has to be specified at construction time.

Each pool maintains a list of free objects of the given type. If sap.ui.base.ObjectPool.prototype.borrowObject is called, an existing free object is taken from the pool. When no free object is available, a new instance is created by calling the constructor without any arguments. In either case, the sap.ui.base.Poolable#init method is called on the object to initialize it with the data for the current caller.

When the object is no longer needed, it has to be returned to the pool by calling #returnObject. At that point in time, sap.ui.base.Poolable#reset is called on the object to remove all data from it. Then it is is added back to the list of free objects for future reuse.

See sap.ui.base.Poolable for a description of the contract for poolable objects.

Example:

  sap.ui.define([
    "sap/ui/base/Event",
    "sap/ui/base/ObjectPool"
  ], function(Event, ObjectPool) {

    // create a pool for events
    var oEventPool = new ObjectPool(Event);

    ...

    // borrow an instance and initialize it at the same time
    var oEvent = oEventPool.borrowObject('myEvent', this, {foo: 'bar'});
    // this internally calls oEvent.init('myEvent', this, {foo: 'bar'})

    // return the borrowed object
    oEventPool.returnObject(oEvent);
    // this internally calls oEvent.reset()

    ...

  }});


Constructor

Creates an ObjectPool for maintaining instances of the given class oObjectClass.

oObjectClass must implement the sap.ui.base.Poolable interface.

new sap.ui.base.ObjectPool(oObjectClass)
Param Type Default Value Description
oObjectClass function

Constructor for the class of objects that this pool should manage


Methods Overview

Method Description
borrowObject

Borrows a free object from the pool. Any arguments to this method are forwarded to the init method of the borrowed object.

sap.ui.base.ObjectPool.extend

Creates a new subclass of class sap.ui.base.ObjectPool with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.base.Object.extend.

sap.ui.base.ObjectPool.getMetadata

Returns a metadata object for class sap.ui.base.ObjectPool.

returnObject

Returns an object to the pool. The object must have been borrowed from this pool beforehand. The reset method is called on the object before it is added to the set of free objects.

borrowObject

Borrows a free object from the pool. Any arguments to this method are forwarded to the init method of the borrowed object.

Param Type DefaultValue Description
args any

optional initialization parameters for the borrowed object

sap.ui.base.ObjectPool.extend

Creates a new subclass of class sap.ui.base.ObjectPool with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.base.Object.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

sap.ui.base.ObjectPool.getMetadata

Returns a metadata object for class sap.ui.base.ObjectPool.

returnObject

Returns an object to the pool. The object must have been borrowed from this pool beforehand. The reset method is called on the object before it is added to the set of free objects.

Param Type DefaultValue Description
oObject object

The object to return to the pool