aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage collection" Watch "Garbage collection" New topic
Author

Garbage collection

Henry Zhi Lin
Ranch Hand

Joined: Nov 04, 2008
Posts: 69
Guys,

this is from devaka's examlab, practice 1, question 68.



the answer is after line 9 we have only one object eligible to GB.

Can anyone draw a diagram for me I am confused here again?


SCJP 5.0
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19061
    
  40

Can anyone draw a diagram for me I am confused here again?


Instead of just trusting the answer, can you tell us what you think the answer should be? After all, I am assuming that you are confused here because you think the answer is something else?

(hint: I don't agree with the answer either)

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Zhi Lin
Ranch Hand

Joined: Nov 04, 2008
Posts: 69
Herny,

the following is what I thought,

after line 6
a1 ---> OA
a2 ---> OB
a3 ---> OC

after line 7
a1 ---> OA --> OD
a2 ---> OB
a3 ---> OC

after line 8
a1 ---> OA --> OD
a2 ---> OB --> OD
a3 ---> OC

after line 9
a1 ---> OA --> OD
a2 ---> OB --> OD
a3 ---> OC --> OD

after line 10
a2 ---> OB --> OD
a3 ---> OC --> OD
which OA should be eligible to GB, so my answer is after line 10 not line 9.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3267
    
  52

Hi Henry Zhi Lin,

Please do not post misleading statements here. You said .....
Originally posted by Henry Zhi Lin:

...the answer is after line 9 we have only one object eligible to GB...


But in my simulator, the correct answer as given is "line 10" (Answer D)! However another time you said,....
Originally posted by Henry Zhi Lin:

...so my answer is after line 10 not line 9....


So, if both you and me said that the correct answer is line 10; then who said, the answer is after line 9?

Due to your posts, others may think that the questions/answers in my simulator are not accurate; as you can see below:
Originally posted by Henry Wong:

hint: I don't agree with the answer either


Because of this, please feel kind to correct this as soon as possible.

Devaka.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Henry Zhi Lin
Ranch Hand

Joined: Nov 04, 2008
Posts: 69
Sorry Devaka, I guess I must misread your answer. I have a suggest on your simulator, would you mind to add save test result function, currently after I exit your simulator everything will not be saved.

Thanks anyway!
Fabio Nascimento
Greenhorn

Joined: Nov 16, 2008
Posts: 16


After line 10



After line 10 you have one Aegis Object eligible for GC, after all you have 4 objects eligible for GC, three that you removed the references manually and one that become unreachable after that.
Rekha Srinath
Ranch Hand

Joined: Sep 13, 2008
Posts: 178
All,

Sometimes I get confused on such situations...

In this code, the 'ags' of a1 is pointing to another Aegis object (lets call it X). Ok..

Now when a1 is made null, there is no meaning for a1.ags, right? which means that object X cannot be reached via a1.ags.

So, if I have the code as:
Aegis a1=new Aegis();
a1.ags=new Aegis();
a1 = null; // Line 1


After Line 1, there are two objects eligible for GC, right?

Please correct me if I am wrong.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

@ Rekha Srinath

Hope the following tell you are Right



Output:
Games
James

[ November 19, 2008: Message edited by: James Tharakan ]

SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Rekha Srinath
Ranch Hand

Joined: Sep 13, 2008
Posts: 178
That was a cool example James !!
Jyothsna Panchagnula
Ranch Hand

Joined: Jul 11, 2005
Posts: 113
Hi James,

Can we say that Fun f and f.f1 are the objects that are garbage collected. ?

thanks,
Jyothsna
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Yes the objects refered BY f anf f.f1
Edmen Tay
Ranch Hand

Joined: Oct 21, 2008
Posts: 39
So, if I have the code as:
Aegis a1=new Aegis();
a1.ags=new Aegis();
a1 = null; // Line 1


So, Can we said that when object reference a1 point to null, then its instance variable reference(a1.ags) will be set to null as well. Am I right?

Please correct, if i am wrong.

Thanks

Regards,
Edmen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage collection