I have the following problem with objects in actionscript3:
var o:Object = new Object();
destroyObject(o);
trace(o); // [object Object]
function destroyObject(obj:Object):void{
obj = null;
trace(obj); // null
}
Since objects are passed by reference in AS3 I assume that the previous code would change o to null, but it doesn’t.
Could someone explain me ‘why’?
Thanks.
Objects are passed by reference, but the reference itself is passed by value. The statement
obj = nullsets the parameterobjto null, which means thatobjno longer references the object, but the object itself is still present, and is still referenced by the variableowhendestroyObjectreturns.