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

Garbage Collection Question from VoodooExam

Sugantha Jeevankumar
Ranch Hand

Joined: Jun 06, 2007
Posts: 93


after line 9 execute, how many objects are eligible for garbage collection?

Options :

a . 0
b . 1
c . 2
d . 3
e . 4

I was confident that the answer is A.But it says the answer is C:2 ...please help me out here....
[ January 10, 2008: Message edited by: sugantha Jeevankumar ]

SCJP 5.0
Alejandro Galvan
Ranch Hand

Joined: Jan 02, 2008
Posts: 48
Hi Sugantha:

Take a look carefully in your code, in line 4 you're creating a new object and refering it with gc2, on line 5 you're creating a second object and refering it with gc3, on lines 6 and 7 you are crossing references, I mean you just are doing that both gc inside your two objects refer to each other, but in line 8 you are creating a new object, this object has its own gc, but it refers to NULL and you are refering it with gc2, finally you are refering this last object which its gc referes to NULL with gc3.

So both reference variables (gc2 and gc3) points to the same object (the one which its gc refers to NULL), the other two objects have no reference alive, you can think "but object1.gc refers to object2 and object2.gc refers to object1, so they still having references alive", the answer is no, since you have no an alive reference variable from your thread which refer to object1 there is no way to access object2 throught object1.gc and viceversa, so both objects have lost their connection to the world, indeed they are elegibles for garbage collector.

Do you get it? I hope this help you to understand it.

Also I want to encourage you to take a look around, there are so many cases about garbage collector in JavaRanch, some of them are quite similar to your doubt.

Regards,


SCJP 5.0<br />Preparing SCWCD
Sugantha Jeevankumar
Ranch Hand

Joined: Jun 06, 2007
Posts: 93
Sorry Alejandro...that was my oversight.Thanks for clearing my doubt
Alejandro Galvan
Ranch Hand

Joined: Jan 02, 2008
Posts: 48
Don't apologize, we all are here to learn and to ask each others; if don't, I would not answer you, I glad that I can help you. Just take a bit time to read other's questions, it helped to understand some things.

Take care

Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection Question from VoodooExam