Packagesekati.collections
Classpublic class Allocator
ImplementsIAllocator

Allocator provides a standardized interface for the bulk allocation of objects in memory. Once populated with objects that need to be cached for application use the allocator will only create new objects when the requests exceeds the allocators cache.

The benefits of using an allocator when generating large amounts of objects is two-fold:

  1. Creation of objects is slow and can effect application performance (especially in bulk scenarios).
  2. Manual management of the bulk creation of objects easily leads to accidental Memory Leaks if the objects are not properly Garbage Collected.


Example
  var allocator : Allocator = new Allocator( AbstractTest );
  var test : AbstractTest;
  
  trace ("Memory Initialized: " + System.totalMemory );
  
  for(var i:int = 0; i < 1000; i++) {
    test = allocator.getObject( );
  }
  trace( "Memory Loop #1: " + System.totalMemory );
  
  allocator.reset( );
  
  trace ("Memory: " + System.totalMemory );
  
  for(var j:int = 0; j < 1000; j++) {
    test = allocator.getObject( );
  }
  trace ("Memory Loop #2: " + System.totalMemory );
  
  allocator.release( );
  trace ("Memory Finalized: " + System.totalMemory );
  



Protected Properties
 PropertyDefined by
  _cache : Array
Allocator
  _index : int
Allocator
  _type : Class
Allocator
Public Methods
 MethodDefined by
  
Allocator(type:Class = null)
Allocator Constructor
Allocator
  
Retrieve an object from the Allocator cache or create a new object if the current cache has been exhausted.
Allocator
  
release():void
Release the Allocator objects from memory when you no longer need the cached objects.
Allocator
  
reset():void
Reset the cache index when you have populated the Allocator cache and are ready to re-use the cached objects.
Allocator
Property detail
_cacheproperty
protected var _cache:Array
_indexproperty 
protected var _index:int
_typeproperty 
protected var _type:Class
Constructor detail
Allocator()constructor
public function Allocator(type:Class = null)

Allocator Constructor

Parameters
type:Class (default = null) — of Class the Allocator class contains.
Method detail
getObject()method
public function getObject():*

Retrieve an object from the Allocator cache or create a new object if the current cache has been exhausted.

Returns
*
release()method 
public function release():void

Release the Allocator objects from memory when you no longer need the cached objects.

reset()method 
public function reset():void

Reset the cache index when you have populated the Allocator cache and are ready to re-use the cached objects.