官术网_书友最值得收藏!

Heap fragmentation

When the JVM starts, it allocates heap memory from the operating system and then manages that memory. Whenever an application creates a new object, the JVM automatically allocates a block of memory with a size that's big enough to fit the new object on the heap. After sweeping, in most cases, memory becomes fragmented. Memory fragmentation leads to two problems:

  • Allocation operations become more time consuming, because it's hard to find the next free block of sufficient size
  • The unused space between blocks can become so great that the JVM won't be able to create a new object

The following diagram illustrates a fragmented memory heap:

To avoid these problems after each GC cycle, the JVM executes a compaction step. Compacting moves all reachable objects to one end of the heap and, in this way, closes all holes. The heap after compacting looks as follows:

These diagrams show how blocks are located before and after compacting. The drawback is that an application must also be suspended during this process.

主站蜘蛛池模板: 衡东县| 淮滨县| 菏泽市| 美姑县| 定安县| 永新县| 呼图壁县| 酒泉市| 凯里市| 焦作市| 平山县| 仪陇县| 天祝| 辽宁省| 海原县| 鄄城县| 宜兰县| 郁南县| 固原市| 广宗县| 西峡县| 宣恩县| 泸西县| 凤城市| 阿巴嘎旗| 卢湾区| 长泰县| 武冈市| 甘孜县| 扎囊县| 甘泉县| 奇台县| 乐至县| 汉寿县| 连云港市| 敦化市| 察哈| 玛多县| 怀柔区| 伊宁县| 桂林市|