Originally posted by Barry Gaunt:
I put a second call to System.gc() into your code and the third object was collected
.....
Instead of a second call to System.gc(), you can try calling Thread.sleep(5000). I did that and all three objects got garbage collected.
When the for loop exits, there are three Test objects on the heap, out of which two are unreachable, where as the third one is referred by reference t. In such a case, how come garbage collector collects all three objects? Is the GC smart enough to "understand" that the reference t is not used anywhere further?
If that is the case, then what would be answer for the following question?
[ August 10, 2006: Message edited by: Neelesh Bodas ]