| Author |
Garbage Collection Question
|
Janki Shah
Ranch Hand
Joined: Nov 23, 2011
Posts: 136
|
|
How many objects are eligible for garbage collection at #1 ?
|
 |
Koen Aerts
Ranch Hand
Joined: Feb 07, 2012
Posts: 344
|
|
|
How many do YOU think there are?
|
 |
Janki Shah
Ranch Hand
Joined: Nov 23, 2011
Posts: 136
|
|
I think 2.
1. new StartBugs() and 2. javas
|
 |
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 869
|
|
the object to which reference variable javas is referring wont be garbage collected because even thought javas is assigned to null, bugs and bugs_INP is referring to it. also at #1 there is this reference to new StartBugs(). so i think zero objects will be garbage collected.
guys correct me if i'm wrong. I myself is little shaky on GC questions so would like to see more posts on this topic. have a great day.
|
OCPJP 6(100 %) OCEWCD 6(91 %)
|
 |
Janki Shah
Ranch Hand
Joined: Nov 23, 2011
Posts: 136
|
|
Hi Gurpreet, The answer is 1 [explanation : "javas is the only object that cannot be reached by the JVM. The this reference will still be available at #1 "]
can you explain little more I don't understand what is happening to this reference?
can someone draw the diagram for it?
|
 |
dennis deems
Ranch Hand
Joined: Mar 12, 2011
Posts: 808
|
|
Janki Shah wrote:can someone draw the diagram for it?
You will benefit a great deal more from a diagram you draw yourself. But you are exactly right to want a diagram; that is the best way, by far, to approach GC questions.
|
 |
 |
|
|
subject: Garbage Collection Question
|
|
|