This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Vector v1 = new Vector() Vector v2 = new Vector() v1 = null//object v1 is eligible for gc Vector v3 = v1;//object v1 is not gced becoz v3 has reference v1 = v2 // object v1 is eligible for gc here once again correct me..
Vector v1 = new Vector() // 1st Vector object is created in heap Vector v2 = new Vector() // 2nd Vector object is created in heap v1 = null // 1st Vector object is eligible gor GC Vector v3 = v1; // v3 ref is null now v1 = v2 // v1 points to 2nd Vector Object // Finally only 1st Vector obj is eligible // for GC. 2nd Vector object is ref.d by // both v1 and v2 not eligible for GC regds maha anna
[This message has been edited by maha anna (edited February 20, 2000).]
The key here is that v1 and v2 are not objects, they are references. References are never collected, but the objects they used to refer to may be. Vector v1 = new Vector() Vector v2 = new Vector() Now reference v1 refers to one Vector object, and v2 refers to another Vector object. v1 = null//object v1 is eligible for gc The Vector which was previously (originally) referenced by v1 is eligible for collection. Vector v3 = v1;//object v1 is not gced becoz v3 has reference Reference v1 is null, so now reference v3 is null also. The Vector which became eligible for GC on the last line is still eligible, as there are no references to it anywhere, and never will be again. v1 = v2 // object v1 is eligible for gc here once again Reference v1 now refers to the same Vector object that v2 does, which has never been eligible for collection (and certainly is not now, because it has two references to it.)
[This message has been edited by Jim Yingst (edited February 21, 2000).]