How does garbage collection work in V8 JavaScript?
V8 uses generational mark-and-sweep (Orinoco). New objects are in the young generation (collected frequently via scavenge). Surviving objects are promoted to the old generation (collected less frequently via mark-sweep-compact). The GC is incremental and concurrent to minimize pauses.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Garbage Collection in JavaScript (V8) Explained
Most objects die young (temp variables, intermediate results). So collecting the young generation frequently is cheap and effective. Old objects are collected less frequently because they tend to survive longer.
V8's modern GC that uses incremental and concurrent marking and sweeping to reduce pause times. Instead of a long stop-the-world pause, marking is done in small steps interleaved with JS execution, and sweeping happens on a background thread.
Closures (keep lexical environments alive), event listeners on detached DOM elements, uncleared timers, global variables, and unbounded caches. These keep objects reachable, so the GC cannot free them.
Still have questions?
Browse all our FAQs or reach out to our support team
