Question

How the performance of the JVM is enhanced by breaking the heap memory in small parts ? such as-

1-Young Generation 2-Old or Tenured Generation 3-Permanent Generation?

Was it helpful?

Solution

It is based on the assumption, that you have 3 types of objects in memory: temporary ones that you do not need after leaving small scopes like methods. long lived ones that you store in data structures intended for long timespans in the life of your applications and some objects, like the class definition itself, which will be never removed. It then turns out there are different methods available to manage the memory and for each one there seems to be a better one: For the young, it seems worth only to save the objects that live longer (called survival/promotion). After that you can clear that whole region. (This is called copy-collection) For the old, you are likely to remove just a few, so you go trough all objects you have and just deal with the ones you no longer need (called sweeping) and for perm, well you don't do anything.

Of course in reality it gets quite complicated, but this model is quite established and works well for many scenarios.

OTHER TIPS

Why is it like this?

Because lots of smart people analysed a lot of Java applications and saw that a vast majority of Objects are short lived ones and they are pretty cheap to both create and destroy. So they made a special place for them in the heap - young generation. This introduces a lot of performance benefits, by keeping this part of the heap rather small, it is much faster to clean memory. Acting on 200MB as opposed to several GB is much faster.

Old Space?

This is where "old" objects go, GC takes more time to clean these objects, but generally is runs much less times then in the young generation.

Permanent generation is removed in Java 8, so you could read about it, but it's soon gone from our radars.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top