Win a copy of Murach's MySQL this week in the JDBC and Relational Databases 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic