• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

gc

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
yesterday i was going through a true/false gc question which made me quite confused. i ended up with two candidate options

1)an object with more than 1 reference will never be garbage collected
2) all members of a method local inner class will be in the garbage collectible heap.

i have to choose one of two...which one will be the answer?? and why
sajid
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 is false. 2 is true. Here's why:

1. "an object with more than 1 reference will never be garbage collected"

False. If you have, let's say, three objects that each have references to the other two, then it can definitely be said that each of those three objects has more than 1 reference. But if all those three objects are created in a method that returns void and doesn't store any of the objects anywhere accessible to a live user thread, then the three objects are considered an "isolated island of objects", or an "island of isolation". They cannot be used anymore by any live user thread, so they all become eligible for garbage collection.

2. "all members of a method local inner class will be in the garbage collectible heap"

True. All members of any class anywhere will be in the garbage collectible heap, because, by definition, the members belong to objects, and all objects created anywhere will be in the garbage collectible heap. Note: "the garbage collectible heap" is another name for "the heap". There is only one heap, and all objects that get made reside there. Don't confuse an object being "in the garbage collectible heap" with being "eligible for garbage collection". They are not the same thing.
reply
    Bookmark Topic Watch Topic
  • New Topic