views:

146

answers:

2

I'm creating a game and I create sprites(enemies). I keep creating and destroying sprites. Flash/Flex has a garbage collector which handles the destruction of unused resources. Should I create an object pool to reuse them, or should I leave flash/flex to handle the creation/destruction of objects?

Which option is better from the performance point of view?

+3  A: 

Leave it to the Flash player to handle and only worry about optimisation if there turns out to be a performance problem. Its all hypothetical until then anyway.

lach
+1  A: 

Object Pooling is an excellent idea if you need to create/destroy lots of items. Flex 4 is doing this with their DataGroup for managing creating destroying itemRenderers while you scroll through huge lists, and it dramatically improves rendering performance.

And all of the particle frameworks HAVE to use this to be competitive.

Check out these Object Pooling Demos and Presentations for Actionscript:

I'd recommend using an object pool if you're creating/destroying lots of objects. Performance optimizations are very important early on if you're building a complex project and you won't have time to go back to it for a while. Object Pooling goes a long way and is very easy to implement.

Hope that helps, Lance

viatropos