mark-and-sweep
The garbage collection method that marks every object reachable from the roots, then sweeps away everything unmarked.
In more detail
It correctly frees circular references that nothing outside reaches. Modern engines are generational: they collect short-lived young objects often and cheaply, and older objects less often.
Related terms
- garbage collection — The automatic freeing of memory held by objects that the program can no longer reach.
- reachability — Whether an object can still be reached by following references from roots such as global variables and the current call stack.
Taught in
- Memory Management: Garbage Collection, Memory Leaks And WeakMap — Frontend Architecture & Web Platform