Meaning
Software condition where available system memory becomes divided into small, non-contiguous blocks that cannot satisfy a single large allocation request. Dynamic heap fragmentation occurs when a wireless module frequently creates and destroys buffers of varying sizes during network operations. This state reduces the effective capacity of the device even when the total free bytes remain high.
Contiguous Gap
Allocation patterns in embedded systems lead to holes between active data structures. Long-running processes that manage complex packet queues are susceptible to this effect. Over time, the heap looks like a checkered pattern of used and unused segments.
A large request might fail because no single hole is wide enough.
Allocation Failure
Request rejection happens when the memory manager finds no single gap large enough for the current task. Even if the total free space is ten times the requested size, the operation fails without a contiguous block. This triggers a watchdog reset or a stack overflow in poorly managed firmware.
Dynamic heap fragmentation is a common cause of unexpected reboots in smart meters and sensors.
Compaction Constraint
Real-time operating systems often lack the overhead for defragmentation algorithms. The system must be designed to avoid fragmentation from the start.