File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 4240
    
    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: 4240
    
    7

So which two variables are pointing at the same object?
 
 
subject: eligible objects
 
Similar Threads
A GC Question
when will it be Garbage collected?
Eligible for garbage collection
garbage collection