- Mastering High Performance with Kotlin
- Igor Kucherenko
- 174字
- 2021-06-25 20:55:22
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.
- Cocos2D-X權(quán)威指南(第2版)
- GeoServer Cookbook
- 樂學(xué)Web編程:網(wǎng)站制作不神秘
- DevOps入門與實踐
- Mastering Kotlin
- C語言程序設(shè)計學(xué)習(xí)指導(dǎo)與習(xí)題解答
- Getting Started with NativeScript
- C語言程序設(shè)計
- 低代碼平臺開發(fā)實踐:基于React
- Extending Puppet(Second Edition)
- Android項目實戰(zhàn):手機安全衛(wèi)士開發(fā)案例解析
- R用戶Python學(xué)習(xí)指南:數(shù)據(jù)科學(xué)方法
- 零基礎(chǔ)學(xué)HTML+CSS第2版
- Mastering OpenStack
- 深入淺出 HTTPS:從原理到實戰(zhàn)