Member-only story
Understanding the JVM Memory Model — Heap vs. Non-Heap
Straightforward and simple

The JVM is a beloved concept that every Computer Science undergrad knows by heart. It’s been with us since 1994, and although it went through quite a few iterations since, it’s still holding strong.
Why should you care about the JVM memory model?
Whether you’re using Java, Kotlin, Scala, Groovy, or even Neo4j for your graph database, you’ve got the JVM working behind the scenes.
So, to have a stronger command in your niche, it makes sense to have some understanding of how it works, and particularly how its memory model is built, unless you happen to be a fan of OOM errors.
Understanding how memory is managed is especially relevant nowadays, as many of us are working with microservices that run inside containers that have a limited memory capacity. If you want to reduce costs and retain your application’s performance, you need to efficiently manage your container’s memory.
Now, you might ask — I’m not a DevOps engineer, how is this relevant for me?
Well, first of all, I personally believe that having a working knowledge of basic concepts, even outside your realm of expertise, is always a good idea. It allows you to be more useful and versatile, and sometimes even come up with creative ideas — connecting the dots between seemingly separate fields. Second of all, it allows you to manage your application better, as you’ll be able to understand the inner workings of your application, allowing you to spot potential issues or even potential areas for improvement.
So, what are we waiting for? Let’s dive in!
One important distinction to make when it comes to JVM memory is where the memory is stored, as it affects various aspects of the application.
We can roughly divide the JVM memory into two parts:
- Heap Memory
- Non-Heap Memory
Let’s start with what most people are already familiar with — Heap memory.
JVM Heap Memory
Broadly speaking, the JVM heap consists of Objects (and arrays).
Once the JVM starts…