Java Programming - Garbage Collections - Discussion

Discussion Forum : Garbage Collections - Pointing out the correct statements (Q.No. 4)
4.
Which statement is true?
Calling Runtime.gc() will cause eligible objects to be garbage collected.
The garbage collector uses a mark and sweep algorithm.
If an object can be accessed from a live thread, it can't be garbage collected.
If object 1 refers to object 2, then object 2 can't be garbage collected.
Answer: Option
Explanation:

This is a great way to think about when objects can be garbage collected.

Option A and B assume guarantees that the garbage collector never makes.

Option D is wrong because of the now famous islands of isolation scenario.

Discussion:
10 comments Page 1 of 1.

Anitha said:   1 decade ago
What is live thread?

Pramod Kumar said:   1 decade ago
Live thread means the program that is being executed currently

Hareendra said:   1 decade ago
How is option (d) incorrect !

They did not specify whether object1 has no live reference.

Santosh said:   1 decade ago
What is live thread is that working concurrently ?

Gayathri said:   1 decade ago
Why not (1) option because we have two methods for calling garbage collector explicitly 1.Runtime.gc() 2.System.gc()

Why not (2) option .. garbage collector uses Mark and Sweep algorithms.

Rajesh said:   1 decade ago
Why not option(B).

The basic garbage collector uses Mark and Sweep algorithms.

Laughingpig said:   1 decade ago
This answer is wrong. If an object X is only referenced by a WeakReference, then that object X is eligible for garbage collection when memory runs low even if the live thread has access to the WeakReference.

Gody said:   1 decade ago
Seems like all are correct. Why C why not all are?

Kinjal said:   1 decade ago
The mark-and-sweep algorithm was the first garbage collection algorithm to be developed that is able to reclaim cyclic data structures. So answer b can be possible too.

Ganesh Mane said:   1 decade ago
The Garbage collector uses mark and sweep method also true.

Post your comments here:

Your comments will be displayed after verification.