Garbage Collector Interactive Simulator

This is an interactive simulator I built to demonstrate how the Garbage Collector operates in Flash Player 9. It allows you to diagram objects and references, then see how reference counting, and mark and sweep routines would play out for your scenario.

It’s pretty easy to use. The object tool (round rect) let’s you click on the stage to add a new object, or click and drag an existing object to create a new object referenced from it. Objects display their reference count in real time. The two reference tools (lines) let you create strong and weak references by dragging from one object to another – the arrow indicates the direction of the reference. The selection tool lets you move/select existing objects and select references. I believe the buttons at the bottom are self explanatory, though it’s worth pointing out that Mark and Sweep are separate buttons. You can use the 1-4 keys to select tools, and the delete key to delete selected items.


Flash Player 8 required.

I built the whole app in ActionScript S3, then had to port it back to AS2 so it would run in my presentation on Resource Management in AS3. It was much easier and more intuitive to write in AS3 than AS2 – I’m really starting to like this language. At some point I might release the code for both, and write about the differences between the two versions.

For more information on how the GC works, you can read this article on the how Garbage Collection works in FP9. If you have any questions, let me know in the comments.

Grant Skinner

The "g" in gskinner. Also the "skinner".

@gskinner

5 Comments

  1. That was informative session at FF. I really enjoyed it.

  2. Hey Grant, great session at FF. This simulator was a really nice touch as was your presoPanel. I liked how the presoPanel loaded in the proper examples for each slide you were looking at. Great job.

  3. hey, could i get the code of the example? it’s great to explain the difference, thats exactly what i was searching for. best regards, sebastian

  4. Thanks for your excellent articles on garbage collection. A question in relation to this: If I initiate an effect, say a Move and halfway into the animation call pause() on the effect and then lose the reference to the original Move because I assign a new Move to the variable used to store the reference, does the garbage collector collect the Move that I can no longer reference?

    Sort of like this:

    private var myMove:Move;

    private function startMove():void

    {

    myMove=new Move(someObject);

    myMove.xTo=100;

    myMove.play();

    }

    private function pauseAndCreateNewMove():void

    {

    if(myMove) myMove.pause();

    myMove=new Move(someObject);

    myMove.xTo=200;

    myMove.play();

    }

  5. Jonas Nyström January 14, 2009 at 12:55am

    Hi Grant!

    Very informative!

    The AS3 code for Garbage Collector Simulator would be great!

    Regards! / Jonas

Leave a Reply

Your email address will not be published. Required fields are marked *