class testfloat { public static void main(String []arf){ A a = new A();// line one object A b = new A();// line 2 object b = a;// after this line is object created at line 2 eligible for gc ??? a = null; } }
vadiraj vd
Ranch Hand
Joined: Dec 15, 2000
Posts: 68
posted
0
Anil, Yes the object created at line 2 may be garbage collected, since there are no active references to this object. regards vadiraj
Regards<BR>---------<BR>vadiraj<P><BR>*****************<BR>There's a lot of I in J.<BR>*****************
vishad patel
Greenhorn
Joined: Dec 05, 2000
Posts: 17
posted
0
hi friend in the given coding the refrence variable at line 2 is not claimed for garbage collection. because it can be reachable through the refrence varible store in the refrence variable b. if you write the coding in the following manner it will be eligible for GC. class testfloat{ public static void main(String args[]){ A a = new A(); A b = new A(); a = null; } } Thanks.
bill bozeman
Ranch Hand
Joined: Jun 30, 2000
Posts: 1070
posted
0
vishad, I don't agree with you. The object that b references in line 2 doesn't have any references once you say that b=a. So that object can be gc'd after you assign b to a. The object that a references is still not eligble for gc after you set it to null because b is now looking at that item also. Bill
umang bhartia
Ranch Hand
Joined: Sep 29, 2000
Posts: 60
posted
0
Anil, the object created at line 2 will b eligible for GC, as u have asigned a new reference to object b, so now there is no reference to the object which has been created at line 2. This is the reason that it will b eligible for GC.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.