• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Simple GC question

 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I'm unable to determine why only (D) is the correct answer to below question.

At a first look I chose (C) & (D) but only (D) is correct.

According to Sun's reply (C) is not correct because even though an object has a valid reference, it still can be garbage collected if no active thread is able to reach it.

My concern is : A valid reference can be considered as valid only if an active thread can reach it. But according to above explanation, it seems my concept has opposite meaning.

Can anyone please explain ?

Which is true?

A) Invoking System.gc() causes the JVM to perform a garbage collection process.

B) Invoking System.freeMemory() causes the JVM to perform a garbage collection process.

C) An object that has a valid reference cannot be garbage collected.

D) Objects created within inner classes can become eligible for garbage collection.
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because there are islands of isolation, where objects have references to each other, but they can still be garbage collected, because no live thread can access them. Object is eligible for GC if no live thread have an access (valid reference) to that object.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one example that I think illustrates the point. Even though the inner class MyClass has a valid reference to a Test object, when there is no valid reference left to the MyClass reference that has a reference to it, a Test object can be garbage collected.

 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yeah. I got the point!!! Thank you for your prompt replies.
 
reply
    Bookmark Topic Watch Topic
  • New Topic