• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java GC | please clear my doubt

 
Mohit K Bansal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Mohit K Bansal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Prithvi for your time. I also have the same understanding.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mohit,

You are welcome.

Best Regards,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic