File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collection

 
anil bisht
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anil,
Yes the object created at line 2 may be garbage collected, since there are no active references to this object.
regards
vadiraj
 
vishad patel
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1070
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic