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

eligible objects

 
ohimai anthony
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When is the B object, created in line 3, eligible for garbage collection?

[Edit - added code tags - see UseCodeTags for details]
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ohimai. Welcome to the Ranch!

There's not actually enough information there to tell - it looks like part of the question is missing. It depends what the s() method of A does. If it doesn't save a reference to b then the B object is eligible for garbage collection after line 5. If it saves a copy of the reference in a then it will be eligible after line 6. But it would be entirely possible for it to do something (like saving a copy in a static reference) that would mean the B object is still not eligible at the end of this code.
 
ohimai anthony
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think because there are two aliases, refferring to the same object, the two ferences have to be nulled or out of scope for the object to be garbage collected.
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So which two variables are pointing at the same object?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic