0% found this document useful (0 votes)
0 views2 pages

In Java

The Old Generation in Java is a part of the heap that stores long-lived objects that have survived multiple garbage collection cycles. Objects are initially allocated in the Young Generation and, after surviving several Minor GCs, are promoted to the Old Generation where they remain until a Major GC removes them. The Old Generation is larger than the Young Generation and is collected using a more expensive GC algorithm, posing a risk of OutOfMemoryError if full.

Uploaded by

splusmm24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

In Java

The Old Generation in Java is a part of the heap that stores long-lived objects that have survived multiple garbage collection cycles. Objects are initially allocated in the Young Generation and, after surviving several Minor GCs, are promoted to the Old Generation where they remain until a Major GC removes them. The Old Generation is larger than the Young Generation and is collected using a more expensive GC algorithm, posing a risk of OutOfMemoryError if full.

Uploaded by

splusmm24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In depth Old gen in gc in Java

- by utk

What Is the Old Generation?


The Old Generation (Tenured Generation) is a region of the Java heap
that stores objects that have survived multiple garbage collection
cycles in the Young Generation.

Think of it as the “retirement home” for objects that the JVM


considers long-lived.

🧱 Heap Memory Layout Recap


pgsql
CopyEdit
+---------------------+--------------------+-----------------+
| Young Generation | Old Generation | Metaspace |
| (Eden + Survivors) | (Tenured) | (class metadata)|
+---------------------+--------------------+-----------------+

🔁 Object Lifecycle Through GC


1. New objects are allocated in Eden (Young Gen).
2. If they survive a few Minor GCs, they are moved to Survivor
spaces.
3. After surviving a set number of GCs (-XX:MaxTenuringThreshold,
default: 15), they are promoted to the Old Generation.
4. Once in Old Gen, they stay there until a Major (or Full) GC
removes them.
🔥 Characteristics of Old Gen
Feature Details
Long-lived objects (e.g. cached data, session
Contains
objects)
Size Larger than Young Gen
Collected by Major GC or Full GC
GC Algorithm Mark-Sweep-Compact (or Region-based in G1)
Performance
More expensive to collect, longer pause times
Impact
Risk If full → OutOfMemoryError: Java heap space

🔍 Example: Old Gen in Action


Suppose you have this:

java
CopyEdit
List<String> cache = new ArrayList<>();

for (int i = 0; i < 1000000; i++) {


cache.add("Data-" + i);
}

If cache is kept as a global variable (or static field), those strings


may survive enough Minor GCs to be promoted to Old Gen.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy