Home / Java Programming / Garbage Collections :: Discussion

Discussion :: Garbage Collections

  1. Which statement is true?

  2. A.
    Calling Runtime.gc() will cause eligible objects to be garbage collected.
    B.
    The garbage collector uses a mark and sweep algorithm.
    C.
    If an object can be accessed from a live thread, it can't be garbage collected.
    D.
    If object 1 refers to object 2, then object 2 can't be garbage collected.

    View Answer

    Workspace

    Answer : Option C

    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.


Be The First To Comment