Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt regarding garbage collection

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
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.

 
meeta gaur
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: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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