Garbage Collector in AS3

The Garbage Collector in AS3 is smart, but it’s driving me crazy.

Being new to AS3, I didn’t realise that removing a child from the display list does not kill all it’s listeners, sounds, and some other stuff I don’t know.

When it affected me, I stopped for a moment and thought why is it built this way. It is true that sometimes, after removing a child from the display list, you do want the listener to stay.

Yet, I don’t see why they didn’t create another function that lets user kill all listeners in a particular child before removing it.

Anyway, after being stuck at this problem for a few agonizing hours, I realised all I need to do, is actually create a if statement inside any listener I want to kill as well, that if it’s parent is already null, i.e. to say it is already removed, then it should kill itself!

A simple solution. Hopefully no new bugs turn up after implementing this as a solution. Keeping my fingers crossed.

If this post helped you in any way, help me in return by clicking on the ad below:

3 Responses to “Garbage Collector in AS3”

  1. Pablo Davi

    U can try use System.gc(); function to send yout ‘trash’ to garbage collector and say: “hey garbage, delete it please man” and be happy :) will speed up the content burn

  2. DarkSuiyoken

    the problem was that GC was thinking the object I had was still in use. hence, the automatic running of the default GC was not cleaning it. :P

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>