You will find that the last array position still holds the MyClass object. Also, the reference to array is not changed from the caller's perspective.
array = X; is an assignment operation that will work to change the contents of this array. However array=null will not assign the reference to null outside this method's body. The caller still holds the reference to the array
dude see.....when you passed the array to the method you create a new variable that contains the position of the array....so this refers to the original array.....but mind you this is a new variable that refers to the same array.... when you null this reference the object is still being referred by the original variable....so it not available for gc....
but using the new ref variable in the method you change the contents of the array....that is you make array, , null....so objects referred by them become available for gc...
Joined: Oct 13, 2009
Thanks Ankit and Ankur, understood. Now i am ready for any question regarding passing object reference to methods.
Special thanks to Ankit, the link you provided was awesome.