Nice discussion going on here, I did some research myself.
The following code will kill performance in your game quite quickly:
public var actorArray : Array;
//This is executed every frame of the game
public function update(list:Array):void
{
actorArray.push(createActor(actorType,0,0,FRONT));
actorArray[actorArray.length-1].kill();
}
The reason why this is so bad is that a reference is kept to the actor in actorArray and then the garbage collector won't release it from memory.
This next bit of code is steady, i.e., in 1000s of actors created:
public var actorArray : Array;
//This is executed every frame of the game
public function update(list:Array):void
{
actorArray.push(createActor(actorType,0,0,FRONT));
actorArray[actorArray.length-1].kill();
actorArray[actorArray.length-1] = null ;
}
However, the last bit of code causes the allocated memory to bounce up and down by 12 MB per second. Which I tested through:
//This is executed every frame of the game
public function update(list:Array):void
{
print(
actorCount +
"min: " + Profiler.minMem +
"max: " + Profiler.maxMem +
"current: " + Profiler.currentMem
);
for (var i=0; i<2; i++){
actorArray.push(createActor(actorType,0,0,FRONT));
actorArray[actorArray.length-1].kill();
actorArray[actorArray.length-1] = null ;
}
actorCount+=2;
}
The constant memory allocation/release is costly for performance, and therefore recycled actors are preferable whenever you can use them.
Whether or not it makes sens to make the engine utilize recycled actors in all cases, i'm not sure. But one thing I see that the engine might improve on is how each time an actor is created, the bitmapdata seems to be copied (the top program stalled my computer in <10 seconds with a 512x512 bitmap, using >500MB of memory). There should be no need to do this copying on every occasion. Instead if custom alteration of bitmap / frame data is used, it seems better to provide a method to initialize this when it is needed. E.g. pixels = pixels.copy();
Another thing I think should be implemented (which I havent seen) is a default destructor method for behaviors (e.g. destroy() or dispose()). This isn't so hard to generate from the attribute lists for design mode, and will help those who write in code mode to clear up after themselves.