How many objects are eligible for Garbage collection in Java?

Regarding Garbage Collection?

  • 1.class Snoochy { 2.Boochy booch; 3.public Snoochy() { booch = new Boochy(this); } 4.} 5.class Boochy { 6.Snoochy snooch; 7.public Boochy(Snoochy s) { snooch = s; } 8.} And the statements 9.public static void main(String[] args) { 10.Snoochy snoog = new Snoochy(); 11.snoog = null; // more code here } Which statement is true about the objects referenced by snoog, snooch, and booch immediately after line 23 executes? A. None of these objects are eligible for garbage collection. B. Only the object referenced by booch is eligible for garbage collection. C. Only the object referenced by snoog is eligible for garbage collection. D. Only the object referenced by snooch is eligible for garbage collection. E. The objects referenced by snooch and booch are eligible for garbage collection. i thought the answer is C but the answer is E.can anyone explain hw is it possible ?? coz in line 11 we have assigned snoog=null.then it should be ready for garbage collection but why its not counted?? pls explain in detail

  • Answer:

    the two classes reference each other. So.. when snoog is created, you also get a booch and a snooch. when you set snoog = null, booch and snooch are eligible for GC,

Krithika at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

its E cus...after line 7 snooch an booch arnt recalled/referenced, hence its ready for garage collection. however my explanation might be wrong as im new to java, and this is how i understand the garbage collection works

Ronnie Bullard

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.