Member-only story

Java Garbage Collection Series (Part 2): Understanding Generational Garbage Collection and Performance Optimisations

Divyansh Tripathi
5 min readOct 10, 2024

--

In the first blog of this series, we introduced the basics of Java garbage collection and how the JVM automatically handles memory management. Now, it’s time to take a deeper dive into generational garbage collection, how the heap is divided into generations, and the mechanics behind this process that optimize Java application performance. We’ll also explore the “mark and sweep” approach, the “stop the world” event, and how tools can help monitor garbage collection.

Garbage collection

Understanding the Heap: Dividing It Into Generations

The JVM’s heap is divided into two main parts: the young generation and the old generation (sometimes called the tenured generation). This division helps optimize garbage collection by segregating short-lived and long-lived objects, which reduces the time spent collecting garbage.

The Young Generation

The young generation is where all new objects are allocated. This section is further divided into three parts:

Sections of the Young Generation

The young generation is split into the Eden space and two survivor spaces (S0 and S1). Here’s how it operates:

--

--

Divyansh Tripathi
Divyansh Tripathi

Written by Divyansh Tripathi

Software Developer, Exploring and Learning

Responses (1)

Write a response