Now that we understand(admit) that garbage collection needs to be put high on the list of importance when it comes to AS3 development – one question remains. How can we improve the garbage cleanup process? That’s where CASA Lib’s display package comes in handy giving you a new set of display objects with inherited optimized functionality such as destroy().
While ActionScript 3.0 provides us with the tools(calls) to properly handle garbage collection, an “automated” solution is preferred. However, I admit having an “automated” solution to garbage collection can be a bit tricky and a bit much to ask for, but CASA Lib’s destroy() functionality definitely provides a great alternative.
CASA Lib’s IDestroyable and IRemovableEventDispatcher
CASA LIb introduces a set of display object such as CasaBitmap, CasaMovieClip, CasaShape, CasaSimpleButton, CasaSprite, and CasaTextField which implement both the IDestroyable and IRemovableEventDispatcher. This implementation includes the following functionality:
destroy(): Removes any event listeners and stops all internal processes to help allow for prompt garbage collection.
removeEventListeners(): Removes all event listeners.
removeEventsForListener(listener:Function): Removes all events that report to the specified listener.
removeEventsForType(type:String): Removes all events of a specific type
So as you see garbage collection does not have to be a painful process, it all depends on your initial approach along with your consistency of that approach. Also, it is about working smarter, not harder. CASA Lib’s solution handles a large portion of the clean up process while allowing you to work less and play harder. 🙂
Curious: For those not using CASA LIb to handle the life cycle of your display objects, can you share with us what you do to alleviate the garbage collection process? Leave your comment below!