1. The OS always allocates contiguous memory space to the JVM
2. When there are more objects created & killed very frequently, the JVM stores them in memory spaces wherever they have free space.
3. This results in a situation called Heap Fragmentation ( same like disk fragmentation ) wherein the heap is fragmented.
4. This makes the JVM not to release the contiguous memory space to OS ( remember, memory is allocated /de-allocated in contiguous memory blocks)
How to Avoid Heap Fragmentation
1.Identify and reduce the frequent creation of unnecessary objects.
2.Compact the Heap by using the option -compactGc option of the JVM ( this comes with a performance penalty )
3. Keep the Max-Heap size setting to as close as possible to the maximum memory required by your JVM