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

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.

主站蜘蛛池模板: 富蕴县| 河曲县| 吉木乃县| 明溪县| 六枝特区| 九台市| 永新县| 台南市| 法库县| 吉首市| 凌海市| 都匀市| 阳新县| 伊吾县| 东乌珠穆沁旗| 滨海县| 宁陕县| 灌云县| 南丹县| 庐江县| 固镇县| 盐源县| 丘北县| 鱼台县| 安新县| 江口县| 嘉鱼县| 泗水县| 新平| 遂溪县| 邮箱| 栖霞市| 寻甸| 磴口县| 盐边县| 柏乡县| 彩票| 土默特左旗| 温宿县| 万山特区| 桐城市|