0

In JConsole I am seeing different heap spaces "Eden", "Survivor", "Old". What is the difference between them?

trincot
  • 317,000
  • 35
  • 244
  • 286
th3falc0n
  • 1,389
  • 1
  • 12
  • 33

1 Answers1

0

Please see the Memory Management in the Java HotSpotTM Virtual Machine whitepaper.

Java divides the heap into two spaces called ‘generations,’ the New generation and the Old generation. The New generation is further divided into Eden and Survivor spaces.

The reason for having New and Old generations is because nearly all objects in a Java program live for only a short period of time, and if the short-lived objects can all be deallocated without examining all the long-lived objects, garbage collection will be much faster. For example, a program will usually have configuration settings and shared data objects that live for the entire life of the program, while objects like StringBuilders are constantly being created that become garbage before the methods that created them even return. Ideally all the temporary objects created after a few method calls could be instantly reclaimed without wasting time looking at anything else.

How does Java distinguish short-lived from long-lived objects? By putting them in different buckets and counting how many garbage collections they survive. Brand-new objects go into the Eden space. The Eden space is frequently garbage-collected, but nearly everything in there is already garbage by the time that it is examined. The few objects that are not garbage get moved into the Survivor space. Objects in the Survivor space get tagged with a count of how many garbage collections they survive. Some become unreachable and get garbage-collected relatively quickly, but others stay reachable, and after they’ve survived some threshold number of garbage collections, Java assumes they are long-lived objects and promotes them into the Old generation.

andrewdotn
  • 32,721
  • 10
  • 101
  • 130