This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes eligible objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "eligible objects" Watch "eligible objects" New topic
Author

eligible objects

ohimai anthony
Greenhorn

Joined: Feb 07, 2012
Posts: 15


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

[Edit - added code tags - see UseCodeTags for details]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4370
    
    8

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

Joined: Feb 07, 2012
Posts: 15
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

Joined: Apr 06, 2010
Posts: 4370
    
    8

So which two variables are pointing at the same object?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: eligible objects