BIT-101 [2003-2017]

AS3 Garbage Collector Note


I made a custom class that extended Sprite, and created an instance. Then I deleted it, but lo and behold, it was still there. After searching live docs and the web for some kind of destroy function or something else, I figured I’d ask one of the smartest humans I know personally, Darron Schall. Of course, he had the answer right there.

In AS2, when you delete an object, the player pretty much grabs it, carries it to the incinerator, shoves it in and watches to make sure it’s completely destroyed. You delete it and it’s gone.

On the other hand, when you delete an AS3 object, it gets put out on the sidewalk in a big green bag for later pickup. Eventually, the garbage collector will come along and take it away. Maybe in the next couple of milliseconds, maybe some time later in the week. If you look, you might still see it there, but it’s not really polite to keep staring at it.

I guess it’s just one of those things that at first kind of bugs you, because you know it’s sitting there, and you want it to be actually gone. But I guess after a while, you have faith that the GC really does take care of it in good time, and you start to relax.

I can’t claim to know much about that stuff, but apparently this is much better, more efficient, etc. Fine with me, now that I know what’s happening. Anyway, just wanted to share that in case anyone else runs into the same thing.

« Previous Post
Next Post »