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

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.

主站蜘蛛池模板: 文化| 军事| 青浦区| 馆陶县| 咸阳市| 营山县| 丰都县| 射洪县| 嵊州市| 葵青区| 兴业县| 东阳市| 湖南省| 济宁市| 南阳市| 凉山| 武夷山市| 绥中县| 临沧市| 阜城县| 广宁县| 五寨县| 苍溪县| 宣恩县| 临潭县| 盐山县| 浙江省| 化州市| 慈溪市| 叙永县| 偃师市| 垫江县| 蒙阴县| 五大连池市| 都兰县| 噶尔县| 美姑县| 华安县| 邵阳市| 尚志市| 通榆县|