This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Java GC | please clear my doubt

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, i did a quick search and found the similar post
https://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
 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mohit,

You are welcome.

Best Regards,
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic