IntelliJ Java IDE
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How many object are eligible for gc - problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "How many object are eligible for gc - problem" Watch "How many object are eligible for gc - problem" New topic
Author

How many object are eligible for gc - problem

Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 89
This is excercise from "ExamLab for SCJP 6.0"
How many objects are eligible for the gc after executing statement "c.aob=null"

I made a graph and I can see only one object eligible for gc. The answer is 2. So can you show me where is my mistake?



SCJP6
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 377
Even i see only one object eligible for GC which was referred by c initially.


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9090

A d = new A().aob =new A();
This is the key line here. There is one object eligible for GC here. The object in bold is actually assigned to d and the object in italics is eligible for GC...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Here:

d points to the last object created with new A(), not the object created with new A().aob.
Object new A.aob is eligible to gc since there is no reference that points to it.
And the total number of objects eligible for gs is 2.

Look at this example.

Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 89
Thanks for clarifying. Now I can see how it works.
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 767
I can smell in air, that why ExamLab is considered to be tough.

I must praise Devaka for putting such a great effort and making it open-source for the community.
My special thanks to Devaka.

Best Regards,


Prithvi/Beenish,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2595

Prithvi Sehgal wrote:... and making it open-source for the community.

Open-Source ???


Author of ExamLab - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 767
Apologies Devaka wrong word i must say. Not open-source.
To my knowledge, before somtime, ExamLab was free , i am not really sure if you have updated it at commercial level.
Let me know.

Best Regards,
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2595

Prithvi Sehgal wrote:i am not really sure if you have updated it at commercial level.

Nope, and never
 
IntelliJ Java IDE
 
subject: How many object are eligible for gc - problem
 
Threads others viewed
How many eligible for GC?
doubt about GC
Garbage collect question
Objects eligible for GC
Garbage Collection Question from Devaka's Exam Labs for SCJP6 - diagnostic exam question number 70.