Algorithms
- Reference Counting — a counter tracks references to an object. At 0 — the object is freed. PHP, CPython. Problem: circular references
- Mark and Sweep — traverses the object graph, marks reachable objects, deletes unmarked ones. Java, Go, JavaScript
- Generational GC — young objects (short-lived) are collected more often than old ones. JVM, .NET, V8
PHP and GC
PHP uses reference counting + a cyclic garbage collector. Circular references (A → B → A) are not freed by reference counting — the cyclic GC handles them. gc_collect_cycles() triggers it manually.
Performance impact
GC pauses can affect latency. Go's GC is concurrent — pauses under 1 ms. Older JVM GC pauses were measured in seconds.