Heap fragmentation occurs when free space is split into separate gaps. An array needs one contiguous chunk, so enough free space in total does not guarantee room for a new allocation. section 10.3.4
A fragmented 1 MB heap
Imagine a 1 MB heap filled with allocated chunks. Collection frees unused chunks, but the gaps remain too small for the next allocation. If the heap cannot grow, compaction moves the remaining chunks together to make contiguous space. section 10.3.4
Moving arrays matters when code uses pointers to them. In an unsafe C# copy routine, fixed keeps the source and target arrays in place until the pointer-based copy finishes. section 10.3.4
The heap after compaction shows why moving allocated chunks can resolve a fragmented layout. section 10.3.4
