Garbage Collection in Flash AS3

I'm blogging about this because it's one area which can be potentially troublesome for people who are switching from the AS2 style of doing things to AS3. One of the big differences about AS3 is the fact that programmers have more control over the heirarchy of Display objects (formerly MovieClips). It's easier now to traverse the list of children of a display object. You can also take a display object from one parent and move it to another. In AS2, removing a Movieclip was a way to delete it. Not so in AS3. I've been running into some issues when using the Loader object. Removing the loader and calling unload on it was not enough to delete the contents of the loader. I could tell because the clips were still playing sounds even though they weren't on the stage. One reason these clips weren't getting deleted is because having an object listen for events creates a reference which will keep that object from being deleted. To help with this situation, adobe has allowed us to hook events with Weak references. Weak references are not counted as a reference, so if only weak references remain, an object should be garbage collected.
Even with weak references, it seems to be a best practice to remove all event listeners when an object is no longer needed. Because of this, I think flash needs deconstructors. There should be a way to signal that an object should be deleted and allow programmers to write code that can clean up that object's resources. Also, it would be nice to have some control over when garbage collection occurs.

