What is garbage collection?
Garbage collection automatically frees memory that’s no longer referenced.
The V8 engine uses the mark-and-sweep algorithm:
- “Mark” reachable objects from the root.
- “Sweep” and delete unreachable ones.
Example:
let user = { name: "John" };
user = null; // eligible for garbage collection