Here is an example of object pool without object count limit.
import flash.utils.Dictionary;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
public class ObjectPool {
public function ObjectPool()
{
throw new Error("don't create instance");
}
private static const objectDict:Dictionary = new Dictionary();
public static function getObject(c:Class):Object{
//if you want add a object count limit,try to check the count here
if (objectDict[c] == null) {
objectDict[c] = [];
}
var t:Array = objectDict[c] as Array;
if (t.length > 0) {
return t.shift();
} else {
return new c();
}
}
public static function putObject(obj:Object):void {
var c:Class = Class(getDefinitionByName(getQualifiedClassName(obj)));
if (objectDict[c] == null) {
return;
}
var t:Array = objectDict[c] as Array;
if (t && t.indexOf(obj) == -1) {
t.push(obj);
}
}
}