User Guide

240 Working with Arrays
If you use myObject as a key in a Dictionary object, you are creating another reference to the
original object. For example, the following code creates two references to an object—the
myObject variable, and the key in the myMap object:
import flash.utils.Dictionary;
var myObject:Object = new Object();
var myMap:Dictionary = new Dictionary();
myMap[myObject] = "foo";
To make the object referenced by myObject eligible for garbage collection, you must remove
all references to it. In this case, you must change the value of
myObject and delete the
myObject key from myMap, as shown in the following code:
myObject = null;
delete myMap[myObject];
Alternatively, you can use the useWeakReference parameter of the Dictionary constructor to
make all of the dictionary keys weak references. The garbage collection system ignores weak
references, which means that an object that has only weak references is eligible for garbage
collection. For example, in the following code, you do not need to delete the
myObject key
from
myMap in order to make the object eligible for garbage collection:
import flash.utils.Dictionary;
var myObject:Object = new Object();
var myMap:Dictionary = new Dictionary(true);
myMap[myObject] = "foo";
myObject = null; // Make object eligible for garbage collection.
Multidimensional arrays
Multidimensional arrays contain other arrays as elements. For example, consider a list of tasks
that is stored as an indexed array of strings:
var tasks:Array = ["wash dishes", "take out trash"];
If you want to store a separate list of tasks for each day of the week, you can create a
multidimensional array with one element for each day of the week. Each element contains an
indexed array, similar to the
tasks array, that stores the list of tasks. You can use any
combination of indexed or associative arrays in multidimensional arrays. The examples in the
following sections use either two indexed arrays or an associative array of indexed arrays. You
might want to try the other combinations as exercises.