aspose file tools*
The moose likes Beginning Java and the fly likes doubt regarding garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt regarding garbage collection" Watch "doubt regarding garbage collection" New topic
Author

doubt regarding garbage collection

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

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.


~ Mansukh
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

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


My one regret in life is that I am not someone else.
- Woody Allen
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157



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.
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

http://www.coderanch.com/t/517562/java-programmer-SCJP/certification/Garbage-Collection?OWASP_CSRFTOKEN=7DVH-WGV3-8OVL-RLCU-1G7D-9M1K-BMN2-4KQ2

http://www.coderanch.com/t/539316/java/java/object-creation?OWASP_CSRFTOKEN=7DVH-WGV3-8OVL-RLCU-1G7D-9M1K-BMN2-4KQ2

http://www.coderanch.com/t/554058/java/java/Garbage-Collection-query?OWASP_CSRFTOKEN=7DVH-WGV3-8OVL-RLCU-1G7D-9M1K-BMN2-4KQ2

http://www.coderanch.com/t/485932/java-programmer-SCJP/certification/GC?OWASP_CSRFTOKEN=7DVH-WGV3-8OVL-RLCU-1G7D-9M1K-BMN2-4KQ2

Now, you should learn SearchFirst.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157




Thank you Meeta.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt regarding garbage collection