Package | sekati.collections |
Class | public class Allocator |
Implements | IAllocator |
The benefits of using an allocator when generating large amounts of objects is two-fold:
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 );
Property | Defined by | ||
---|---|---|---|
_cache : Array | Allocator | ||
_index : int | Allocator | ||
_type : Class | Allocator |
Method | Defined by | ||
---|---|---|---|
Allocator(type:Class = null)
Allocator Constructor
| Allocator | ||
getObject():*
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 |
_cache | property |
protected var _cache:Array
_index | property |
protected var _index:int
_type | property |
protected var _type:Class
Allocator | () | constructor |
public function Allocator(type:Class = null)
Allocator Constructor
Parameterstype:Class (default = null ) — of Class the Allocator class contains.
|
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.