References, garbage collection, and leaks

Can the object be collected while the reachable map keeps it?

Examples

Worked example

Input
A cache map still holds an object after the local variable is cleared.
Expected output
No.

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The cache still provides a path to the object, so the object remains reachable.

Back to the lesson