This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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: 4339
    
    7

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: 4339
    
    7

So which two variables are pointing at the same object?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: eligible objects
 
Similar Threads
garbage collection
when will it be Garbage collected?
A GC Question
Eligible for garbage collection