Simple Generic Object Pooling in AS3

For Flash and Flex, object pooling is very important for performance, also an efficient way to avoid memory leak. Although many developers should have found good way to implement pooling, I unable to google a good one fitting my needs. So here’s my simple solution.

You could find source code here:

Basically, a pool could store any kinds of object (maybe sprite, UIComponent), as long as it implements IReusable interface.

  • function cloneNewObject():IReusable;
  • function reset():void;

Basically, the pool will be set with a single object as seed (also first object), any new object will be made by cloneNewObject() function, and stored in a single array. You can put object back, and first not-in-use object in the array will be picked when asking.

Outside of the object pool, you may set one or multiple array or/and dictionary to keep references of these objects for different purpose if necessary.

1 Comment so far »

  1. Gary Paluk said

    am November 27 2012 @ 2:37 am

    Great resource, after looking at your project, I’ve provided a more modern and generalized approach to an object pool here:

Comment RSS

Leave a comment

Name: (Required)

eMail: (Required)