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

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.

主站蜘蛛池模板: 富宁县| 高州市| 鹤山市| 喀喇沁旗| 安塞县| 日喀则市| 海丰县| 潜山县| 九龙县| 介休市| 北海市| 宁城县| 岐山县| 化德县| 庆安县| 巫溪县| 竹北市| 锡林浩特市| 通州区| 武冈市| 比如县| 临泉县| 平潭县| 望谟县| 商丘市| 壤塘县| 乌恰县| 龙海市| 五峰| 西峡县| 长乐市| 丘北县| 永泰县| 新营市| 石门县| 益阳市| 临江市| 漯河市| 舒兰市| 高尔夫| 陆川县|