Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
Hi Suchak Java creates an object named on heap ( which is the array name ) which has three pointers ( I am talking how JVM implements it ). Then, it creates three objects on heap like new XYZ("sss") and so on. Each pointer in the first object points to one object on heap e.g. the first pointer will point to the object new XYZ("sss") and second to new XYZ("sss1") and so on. Finally, the refernece variable a ( as indicated by you in Array a) points to the array object on heap itself. So now you have four objects on heap, 1) array itself, 2) three object which you used to initailize the array. The refernce link is a -> to array --> each object (3 object here ) . If you set a = null then the first refernce link a - > array is broken. Now when garbage collector looks at array object then it sees there noone refers to this object , so it can be garbage collected and since array itself can be garbage collected, so can be other three objects. So setting a = null makes all four objects on heap a candidate for garbage collection, unless all ( or some ) the three objects makes themself reachable in their finalize method. Replies: |
Sponsored Links
|