- 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.
- Microsoft Application Virtualization Cookbook
- .NET 4.0面向對象編程漫談:基礎篇
- TestNG Beginner's Guide
- QGIS:Becoming a GIS Power User
- 深入理解Android:Wi-Fi、NFC和GPS卷
- Extending Puppet(Second Edition)
- 軟件品質之完美管理:實戰經典
- 青少年信息學競賽
- Regression Analysis with Python
- Microsoft Exchange Server 2016 PowerShell Cookbook(Fourth Edition)
- 面向對象程序設計及C++(第3版)
- PostgreSQL Developer's Guide
- Less Web Development Cookbook
- JavaScript編程精解(原書第3版)
- C++標準庫(第2版)