markandcompact
Mark-and-compact, also written mark-compact, is a garbage collection algorithm used in managed runtime environments to reclaim unused memory and reduce fragmentation. It combines two phases: marking and compaction.
During the mark phase, the collector traverses the object graph starting from root references (such as global
In the compaction phase, the collector moves live objects so that they occupy contiguous memory, eliminating
Advantages of mark-and-compact include elimination of memory fragmentation and improved spatial locality, which can enhance allocation
Disadvantages include the need to move objects and update all references, which can be expensive and may