I’m wondering if anyone can answer this question for me.
Suppose I create an instance of a class object:
var holderObject:HolderObject = new HolderObject();
addChild(holderObject);
As part of the HolderObject’s constructor code it allocates 10 new instance variables:
var mcArray:Array = new Array();
for (var i:uint = 0; i > 9; i++) {
var newMC:MovieClip = new MovieClip();
newMC.addEventListener(MouseEvent.CLICK, doSomething, false, 0, true);
mcArray.push(newMC);
addChild(newMC);
}
If I now set holderObject = null;
Will any of those memory allocations be available for garbage collection?
or would I need to explicitly undo the steps I made i.e.:
destroyHolder(holderObject);
function destroyHolder(theHolder:HolderObject):void {
for (var i:uint = 0; i > 9; i++) {
theHolder.mcArray[i].removeEventListener(MouseEvent.CLICK, doSomething);
theHolder.removeChild(theHolder.mcArray[i]);
theHolder.mcArray.splice(theHolder.mcArray.length-1, 1);
}
removeChild(theHolder);
theHolder = null;
}
Yes, they will be garbage collected if there are no other references to those objects.
Understanding garbage collection in Flash Player 9