Memory Management/Memory Compacting

From Wikibooks, open books for an open world
Jump to: navigation, search


As a memory pool is allocated from, over time the pool will become fragmented. Some objects from the pool will be allocated surrounded by objects that are not, in seemingly random order. Memory compaction is the process of moving allocated objects together, and leaving empty space together.

Consider a system with 3 pages and about 50% of their objects are allocated. By compacting all the living objects into the first two pages, leaving the third page completely empty. This empty page can then be ignored during future mark/sweep phases since it is known to be empty of living objects, or it can be released and returned to the operating system.