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.