Java Programming - Garbage Collections - Discussion

Discussion Forum : Garbage Collections - Pointing out the correct statements (Q.No. 2)
2.
Which statement is true?
All objects that are eligible for garbage collection will be garbage collected by the garbage collector.
Objects with at least one reference will never be garbage collected.
Objects from a class with the finalize() method overridden will never be garbage collected.
Objects instantiated within anonymous inner classes are placed in the garbage collectible heap.
Answer: Option
Explanation:

All objects are placed in the garbage collectible heap.

Option A is incorrect because the garbage collector makes no guarantees.

Option B is incorrect because islands of isolated objects can exist.

Option C is incorrect because finalize() has no such mystical powers.

Discussion:
3 comments Page 1 of 1.

Surya said:   1 decade ago
Garbage collector is all so collecting of unused memory/referenced memory.

Corrie said:   1 decade ago
All objects are actually not placed in the garbage collectible heap. Only ones that can be garbage collected.

Objects that are instantiated in an anonymous class might still be used, because they are still in scope. They are not just on a garbage heap because they are in an anonymous class.

B. is correct, because the "islands of isolated objects" actually exist because they are referenced in a circular way, and cannot therefore be garbage collected.

Alexander Monakhov said:   1 decade ago
void f()
{
Object o = new Runnable() { public void run() {} };
}

'o' is allocated on stack, or JIT used is just a crap.

Post your comments here:

Your comments will be displayed after verification.