Card 09/ 09

RecapDifficulty: Advanced1 min

Two Regions, One Rule, Two Errors

Five things this topic established, and where each one was.

What the topic established, and which card it was on
The thingWhere
Variables live in stack frames; every object lives on the heapWhere a Value Lives While Your Method Runs
An object survives while a path from a root reaches it, and no longerWhat Keeps an Object Alive
A stack overflow is recursion; an out-of-memory is reachable objectsStackOverflowError Against OutOfMemoryError
System.gc() requests a collection and cannot free anything reachableWhy System.gc() Is a Suggestion
A leak is code holding references it has no use forA Memory Leak in a Language That Collects Memory

The one worth carrying: reachability, not usefulness, is the whole rule. The collector has no idea what you are finished with, so anything still on a path from a static field, a live frame or a running thread stays exactly where it is.