• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

doubt regarding garbage collection  RSS feed

 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am doing assignment questions given at end of SCJP book. Have a look at following code snippet:



The question is how many objects are available for GC at end ? The answer is 1. Can someone please (if possible with a diagram) explain how? I can see that 4 distinct objects (2 of Beta type and 2 of Alpha type) have been created on the heap. What do we mean when we say ? And in the end we are setting a1, b1, b2 to null. Then how come only 1 object is available for GC? A simple clear-cut explanation would be really helpful.

 
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search-first
http://www.coderanch.com/t/596101/java-programmer-SCJP/certification/Garbage-Collection?OWASP_CSRFTOKEN=B0TM-AQ2M-LMX6-1W2N-INXM-KFE4-V3AX-JZCJ
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

meeta gaur wrote:Search-first
http://www.coderanch.com/t/596101/java-programmer-SCJP/certification/Garbage-Collection?OWASP_CSRFTOKEN=B0TM-AQ2M-LMX6-1W2N-INXM-KFE4-V3AX-JZCJ



This post does not justify the answer that only 1 object is available for GC. My question is how come only 1 object is available for GC when we are explicitly setting 3 object references to null.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!