Back to results for “Performance”
JavaScript › Memory Management & Garbage Collection

What is the difference between the generational garbage collection strategy's 'young' and 'old' generations?

Intermediate

Answer

Most objects die young (short-lived, like temporary variables in a function), so V8's generational GC checks a small 'young generation' heap frequently and cheaply; objects that survive several collections get promoted to the 'old generation', which is scanned less often since long-lived objects are less likely to become garbage soon.
// Conceptual, not code the developer controls directly:
// Young gen: fast, frequent 'Scavenge' collections
// Old gen: slower, less frequent 'Mark-Sweep-Compact' collections
Real-world example Understanding why creating many short-lived temporary objects in a hot loop is usually cheap, since the young-gen collector is optimized for exactly that pattern.

Common follow-ups: Why does frequent promotion of objects to the old generation hurt performance?