I want to know about the Object type specifically when it comes to garbage collection in Flash.
I know that items will be ready for garbage collection in situations like this:
// create
var ar:Array = [];
var mc:MovieClip = new MovieClip();
mc.addEventLisntener(blah, blah);
ar.push(mc);
addChild(mc);
// kill & gc
ar.splice(0, 1);
mc.removeEventListener(blah, blah);
removeChild(mc);
But how/will an Object get garbage collected in situations like below.
Say I have a function in my class MartysMC that I parse an Object through:
package
{
import flash.display.MovieClip;
public class MartysMC extends MovieClip
{
/**
* Updates this
* @param obj An object containing key/value pairs to represent new property values
*/
public function update(obj:Object):void
{
var i:String;
for(i in obj)
{
this[i] = obj[i];
}
}
}
}
And now I make use of this function like so:
var mmc:MartysMC = new MartysMC();
var dataObject:Object =
{
x: 10,
y: 34,
alpha: 0.6
};
mmc.update(dataObject);
What happens to dataObject? Will this get garbage collected from here? Even still, what about the object in this line:
mmc.update({x:15,y:18,name:"marty"});
To see what happen with the GC you can use a Dictionary with a weak reference set to true and using the object you want to cheeck as a key:
when the object will not be longer available it will be delete from the dictionary.
here a complete sample based on your example at wonderfl :
http://wonderfl.net/c/e9W4
you see that very quickly both of your object have been garbage collected.