Get the latest tech news

How ZGC allocates memory for the Java heap


This post explores how ZGC, one of the garbage collectors in the OpenJDK, allocates memory for the Java heap, focusing on enhancements introduced in JDK-8350441 with the Mapped Cache. A garbage collector does much more than just collect garbage - and that’s what I want to unpack in this post. Whether you’re a Java nerd yearning for details, a GC enthusiast, or just curious about how ZGC uses memory behind the scenes, this deep dive is for you.

This post explores how ZGC, one of the garbage collectors in the OpenJDK, allocates memory for the Java heap, focusing on enhancements introduced in JDK-8350441 with the Mapped Cache. If latency is a critical concern, you should disable uncommit, either explicitly by using the-XX:-ZUncommit flag, or implicitly by setting the minimum and maximum heap sizes to the same value. While this is rarely an issue, it’s worth noting that, for historical reasons, the maximum number of memory mappings on Linux is by default set to 65530, which is relatively low.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Java

Java

Photo of Memory

Memory

Photo of zgc

zgc

Related news:

News photo

Pike – a dynamic programming language with a syntax similar to Java and C

News photo

Cache loop and memory loss in GPT – a user-side fix (tested with GPT itself)

News photo

Preserving Ireland's Bogs– Memory, Identity, and the Path Forward