User Guide
Associative arrays 239
Use the for..in loop for direct access to the object keys of a Dictionary object. You can also
access the values of the Dictionary object with the property access (
[]) operator. The
following code uses the previous example of the
groupMap dictionary to show how to iterate
through a Dictionary object with the
for..in loop:
for (var key:Object in groupMap)
{
trace(key, groupMap[key]);
}
/* output:
[object Sprite] [object Object]
[object Sprite] [object Object]
[object Sprite] [object Object]
*/
Use the for each..in loop for direct access to the values of a Dictionary object. The
following code also uses the
groupMap dictionary to show how to iterate through a Dictionary
object with the
for each..in loop:
for each (var item:Object in groupMap)
{
trace(item);
}
/* output:
[object Object]
[object Object]
[object Object]
*/
Object keys and memory management
Flash Player uses a garbage collection system to recover memory that is no longer used. When
an object has no references pointing to it, the object becomes eligible for garbage collection,
and the memory is recovered the next time the garbage collection system executes. For
example, the following code creates a new object and assigns a reference to the object to the
variable
myObject:
var myObject:Object = new Object();
As long as any reference to the object exists, the garbage collection system will not recover the
memory that the object occupies. If the value of
myObject is changed such that it points to a
different object or is set to the value
null, the memory occupied by the original object
becomes eligible for garbage collection, but only if there are no other references to the original
object.