objParam is not the same reference to created object as obj. Whenever you
set objParam to null it becomes null (try checking it out in your
deleteObject method). But who said the obj should become null? To prepare
obj for garbage collection you should set obj to null.
R.
On 6/7/07, Ravi Kumar Gummadi <[EMAIL PROTECTED]> wrote:
Hi all
How does flex handle parameter passing, as I understand, it is by Pass
by reference. But I was having some memory leaks and playing around a
few tweaks and the following snippet completely took me by surprise.
// CODE START
<script>
public var obj:Object;
createObject(){
obj = {test:"1234",test2:"5678"};
}
checkObject(objParam:Object){
trace(objParam);
}
deleteObject(objParam:Object){
objParam = null; // I tried objParam = undefined as well
}
</script>
<mx:Button id="create" click="createObject()" />
<mx:Button id="check" click="checkObject(obj)" />
<mx:Button id="delete" click="deleteObject(obj)" />
// END
Now 1. I created the object by click on create
2. Then check for the existence of it (Traces [object object].. This
is fine)
3. Then clicked delete.
4. Then again click on check... (Traces [object] [object]
!!!!!!!!!!!!!!!!!!!!! But since its passed by reference it should be
NULL)
Somewhere I read that it setting to NULL changes the reference count,
does that mean in each of my function I need to set all the params to
null at the end of it so that refercne count is reduced and raady for
garbage collection!! ( That doesn't quite a sense !!)
Regards
Ravi