How does garbage collection work in JavaScript engines?

Updated Feb 17, 2026

Short answer

JavaScript engines use mark-and-sweep garbage collection to reclaim unused memory.

Deep explanation

Modern engines use generational garbage collection. Objects are allocated in young generation space. If they survive multiple collections, they move to old generation. Mark-and-sweep identifies reachable objects and frees unreachable memory. Incremental and concurrent GC reduce blocking time.

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More JavaScript interview questions

View all →