Introduction

An automatic memory management mechanism.

// Without GC, need to manage memory manually (C/C++ style).

Garbage

An object is garbage when:

public void test() {
  Person p = new Person("Alice");
  p = null; 
  // Now the Person object is garbage
  // End of method, no reference pointing
}

Reachability

Starting points GC trusts as alive: