So I assume that you all have with you GCExample.fla open in Flash IDE. It has 6 frames. In frame 1 you find 5 buttons, each will be responsible for taking you to frame 2 to 6, which in turns will test a certain scenario.

The very first scenario on frame 2 is to test the property of a strong keyed dictionary. If you are wondering why class Dictionary, the reason is according to ActionScript API document of class Dictionary, the default constructor new Dictionary() creates a dictionary whose object keys are strong referenced. In other words, these keys are not eligible for gabarge collection. On the other hand, using new Dictionary(true) instructs the Dictionary object to use weak references on object keys, thereby enabling these keys to be garbage collectable. Thanks to this property of the Dictionary class, we now have a very interesting capability: object counting. To achieve this we create a new Dictionary object which use weak object keys. We then use the object of interest as a new key and assign the value at that key to anything, maybe a primitive, for example:

var aDict:Dictionary = new Dictionary(true);
var aObject:Object = new Object();
aDict[aObject] = 1;


aObject is the object we want to keep track. To know if it has been garbage collected or not, we simply count the number of keys in aDict object, provided that we don't add any more key to aDict.

var n:int = 0;
for (var key:* in aDict) {
    n++;
}


If n equals 0, aObject has been freed, otherwise n equals 1.

With that in mind, we shall now find out if Dictionary really behaves as documented. Frame 2 code is as follows:

var myArray:Array = new Array();
var strongDict:Dictionary = new Dictionary();

addEventListener(Event.ENTER_FRAME, enterFrameStrongDic);

function enterFrameStrongDic(aEvent:Event):void
{
    var anArray:Array = new Array(10000);
    for (var i:int = 0; i < anArray.length; i++) {
        anArray[i] = 0;
    }
    strongDict[anArray] = 1;
    var n:int = 0;
    for (var key:* in strongDict) {
       n++;
    }
    trace("Number of keys " + n);
}


First, a Dictionary object named strongDict, which use strong reference on object keys, is created. Then in every frame onwards, an array of 10,000 integers is created and added as an object key to strongDict. The number of keys in strongDict is counted and printed out every frame as well.
Run GCExample.fla and click on the top button labeled "Test Dictionary Strong" to see the result of the code. You'll see a text box at the bottom, which displays total memory Flash player is using. Without a doubt, the amount of consumed memory steadily increase, so does the number of keys. This proves that those arrays we created in function enterFrameStrongDic are not freed. If we hadn't put them in the Dictionary, they would have been freed, since they are local to enterFrameStrongDic and normally will be freed when reaching the end of that function.

Rerunning GCExample.fla and clicking on the second button from top, labeled "Test Dictionary Weak", will put the code in frame 3 to test.

var weakDict:Dictionary = new Dictionary(true);
addEventListener(Event.ENTER_FRAME, enterFrameWeakDic);

function enterFrameWeakDic(aEvent:Event):void
{
    var anArray:Array = new Array(10000);
    for (var i:int = 0; i < anArray.length; i++) {
        anArray[i] = 0;
    }
    weakDict[anArray] = 1;
    var n:int = 0;
    for (var key:* in weakDict) {
        n++;
    }
    trace("Number of keys " + n);
}


This chunk of code is almost identical to the one in frame 2, except that weakDict, a Dictionary object which uses weak references on object keys, is utilized instead. This time the amount of consumed memory stays the same after an initial increase, also the number of keys remains 1. This outcome is exactly what we expected: GC constantly freed up the arrays that we constantly created.

Since we're now understood and can confidently use the Dictionary class, let's move on to another topic that a lot of people are concerned with: event listeners.