When you set it to null it removes the reference the current scope or context, and when you pass it into that function it is in a different scope from this. had you done this.obj = null, then it would have been completely de-referenced and eligible for garbage collection. > --- In [email protected], "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 >> >> > > > >

