What is the difference between a mark-and-sweep collector and a copying collector?
Correct! Well done.
Incorrect.
The correct answer is C) Mark-and-sweep traverses from roots to mark live objects and then frees unmarked memory in place; a copying collector instead copies live objects into a new region, naturally compacting memory and leaving fragmentation behind
Correct Answer
Mark-and-sweep traverses from roots to mark live objects and then frees unmarked memory in place; a copying collector instead copies live objects into a new region, naturally compacting memory and leaving fragmentation behind
Mark-and-sweep can leave the heap fragmented since dead objects are freed in place. Copying collectors (e.g., semispace) relocate live objects to a contiguous region, which compacts memory and makes allocation a simple pointer bump, at the cost of needing extra space and updating references.