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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Java GC | please clear my doubt" Watch "Java GC | please clear my doubt" New topic
Author

Java GC | please clear my doubt

Mohit K Bansal
Greenhorn

Joined: Mar 06, 2010
Posts: 3
I have some confusion with this code (source:http://examsguide.com/scjp/freequestions2.html [Q. 13]):

After line 6, how many objects are eligible for garbage collection?

Ans: 1
Ans: 2
Ans: 3
Ans: 4
None of the above

The correct answer is 2 (according to the site) but its not clear to me why its 2. Will you guys please explain me. Thanks in advance.
Mohit K Bansal
Greenhorn

Joined: Mar 06, 2010
Posts: 3
Guys, i did a quick search and found the similar post
http://www.coderanch.com/t/452512/java-programmer-SCJP/certification/help-garbage-collection

I was also thinking that "only one object will be available after GC" but the site says 2. I think they need to correct the answer.

Regards,
Mohit
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello,

I have run the sample on paper. To me the answer is 1 because only the object which got created inside m1
is available for garbage collection as no living references exist. I guess this site needs to update their answer
or may be the question source is incomplete because it calls some other method after that its a dead-end. So
answer is 1.

Hope this helps,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Mohit K Bansal
Greenhorn

Joined: Mar 06, 2010
Posts: 3
Thanks Prithvi for your time. I also have the same understanding.
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello Mohit,

You are welcome.

Best Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java GC | please clear my doubt
 
Similar Threads
How many objects?
Garbage Collection
Doubt - Reg: GC
garbage collection
help in garbage collection question