JavaScript · Senior · Question 9 of 75
What conditions guarantee that the garbage collector will remove an object?
- ✓Correct answer: The object is unreachable from the roots (globals, the stack, closures)
- 2Its reference count dropped to zero after assigning
null - 3More than 60 seconds have passed since the object was last accessed
Explanation
Modern engines use mark-and-sweep: everything reachable from the roots is alive. Circular references between unreachable objects don't prevent their removal - unlike reference counting. The timing of collection is unspecified.