Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection Question

 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many objects are eligible for garbage collection at #1 ?

 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many do YOU think there are?
 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think 2.
1. new StartBugs() and 2. javas
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic