GC tự động reclaim memory không còn được reference. Thuật toán cơ bản: Mark-and-Sweep (mark reachable objects từ roots, sweep unmarked); Reference Counting (Python: mỗi object đếm số references, về 0 thì free — không xử lý được circular references nên có cyclic GC bổ sung).
JVM (G1GC/ZGC): generational GC (young gen/old gen/metaspace) vì hầu hết objects chết sớm; minor GC thường xuyên cho young gen; major/full GC cho old gen — là nguồn Stop-The-World pause. ZGC (experimental từ Java 11, production-ready từ Java 15) và Shenandoah: concurrent GC với pause < 1ms dù heap hàng trăm GB.
Go GC: non-generational, concurrent tri-color mark-and-sweep; GOGC=100 trigger GC khi heap tăng gấp đôi; target < 1ms STW.
V8 (Node.js): generational, Orinoco concurrent GC; young gen dùng Scavenge (semi-space copy); old gen dùng Mark-Compact.
Thực tế: GC pressure là vấn đề performance — giảm bằng cách tái sử dụng objects (Go sync.Pool), giảm allocation trong hot path, tune heap size.
GC automatically reclaims memory that is no longer referenced. Core algorithms: Mark-and-Sweep (marks all objects reachable from roots, then sweeps and frees unmarked ones); Reference Counting (used in Python — each object tracks its reference count and is freed when it reaches zero; cannot handle circular references without a supplemental cyclic GC).
JVM (G1GC/ZGC): generational GC (young gen/old gen/metaspace) because most objects die young; minor GC runs frequently on the young generation; major/full GC targets the old generation and is a source of Stop-The-World pauses. ZGC (experimental since Java 11, production-ready since Java 15) and Shenandoah achieve concurrent GC with pauses under 1ms even on hundred-gigabyte heaps.
Go GC: non-generational, concurrent tri-color mark-and-sweep; GOGC=100 triggers a GC cycle when the heap doubles in size; targets STW pauses under 1ms.
V8 (Node.js): generational with the Orinoco concurrent GC; the young generation uses Scavenge (semi-space copying); the old generation uses Mark-Compact.
In practice, GC pressure is a performance concern — reduce it by reusing objects (Go sync.Pool), minimizing allocations in hot paths, and tuning heap size.