Tushar Gosalia wrote:So in this below given program how many objects will be eligible for GC??
1)public class Island {
2)Island i;
3)public static void main(String [] args) {
4)Island i2 = new Island();
5)Island i3 = new Island();
6)Island i4 = new Island();
7)i2.i = i3;
8)i3.i = i4;
9)i4.i = i2;
10)i2 = null;
11)i3 = null;
12)i4 = null;
// do complicated, memory intensive stuff
The Thing Which I'm Not Getting Is,Is the value of i2.i is being assigned to i3 or the value of i3 is being assigned to i2.i.
}
}
Tushar Gosalia wrote:Here i2, i3, and i4 are references which are null at the end..and hence they are eligible for GC but as far as I know only objects are eligible for GC.."BIG CONFUSION"
Tushar Gosalia wrote:Since at line 15 a1, b1, b2 are assigned to null,so why they are not eligible for GC and at line 5 b1 is static does it makes any difference??
OCPJP SE6
Consider Paul's rocket mass heater. |