18 March 2008

Use Weak References for Your Event Listeners

Please read this:

http://www.gskinner.com/blog/archives/2006/07/ as3_weakly_refe.html

Using weakly referenced event listeners means an object can be cleared during Garbage Collection even if there's an event listener acting upon it.

It's very useful when you're spawning / deleting a lot of objects, in my case bubble "bullets" that I'm firing at targets underwater.

It saved my bacon (and my forehead) as I've been banging my head on my desk wondering why objects I thought I'd removed still persisted in memory.

The fact it's not a default setting and not very well explained, nor is its importance highlighted (this should be stapled to the front of the Flash CS3/Flex DVD box), is bloody annoying.

Thanks Grant.

No comments: