aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection :exam lab 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 "Garbage Collection :exam lab" Watch "Garbage Collection :exam lab" New topic
Author

Garbage Collection :exam lab

Sudhakar Duraiswamy
Ranch Hand

Joined: Dec 20, 2007
Posts: 43
Hi,


Could some explain me how the answer is Line 10.


Q: After which line only one object is eligible for GC


Here is my derivation

Situation at Line 9



at Line 10



so my answer was Line 11


how is it Line 10
Source :Exam Lab


Sudhakar
SCJP 5.0 93%| SCWCD (prep. ongoing))
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

From where the object a4 came?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

Sudhakar Duraiswamy wrote:
how is it Line 10
Source :Exam Lab


After line 10 is executed, how do you reach the object that was created on line 4?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Sudhakar Duraiswamy
Ranch Hand

Joined: Dec 20, 2007
Posts: 43
@Abimaran a4 is the object that was newly created at line 7 . I gave it a name a4 for reference.

@henry:
I didnt understand .Could you please elaborate your question





Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Sudhakar Duraiswamy wrote:@Abimaran a4 is the object that was newly created at line 7 . I gave it a name a4 for reference.

@henry:
I didnt understand .Could you please elaborate your question


Check this figure, I manage to draw it . In the line 10, the object, previously referred by a1, has no reference. So it's eligible for GC
ravi keshri
Greenhorn

Joined: Jun 30, 2010
Posts: 3
hiiiii sudhakar
i think for any object which is eligible for garbage collection the condition is that there should no refercence varible exist or by any way we cannot access that object.
in your question you can see after line 10 one object is eligible for gc.
thanks......have a good day.
Faisal A Khan
Greenhorn

Joined: Jul 02, 2010
Posts: 11
Just to elaborate Ravi's point. Please note the object reference contained in a1 has already been copied to the other objects. Hence only a1 is eligible after line 10
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection :exam lab