tags:

views:

664

answers:

4

I'm confused with Heap,Young,Tenured and Perm generation.

Could anyone please explain?

+3  A: 

That's not easy to explain in a few lines. You could read this, but I realise that's a big junk to read. So for some kind of summary of that document: click here

Fortega
+6  A: 

All objects in the heap survive will they are being referenced. When they're not more, the garbage collector (GC) will reclaim their memory.

PermGen, Young and Tenured are diferent clasifications of objects (or spaces in the heap where they can be).

PermGen: these objects will be always there, they're not garbage collected. Classes objects are there, interned strings, etc. I don't know if there is a GC there (when system UNloads classes... but it's not a normal thing)

Young: when an object is created it's here.

Tenured: an object goes to this classification/category when it survives N GC passes (survive = GC passes but this object is referenced so it can't be reclaimed).

Depending of GC used and some parametrization, GC passes more or less often.

Then garbage collection can have different approaches to maange objects in the heap. This classification of objects helps to do it.

helios
If you really like this kind of memory management thing read what Fortega recommends.
helios
+7  A: 

The Java garbage collector is referred to as a Generational Garbage Collector. Objects in an application live for varying lengths of time depending on where they are created and how they are used. The key insight here is that using different garbage collection strategies for short lived and long lived objects allows the GC can be optimised specifically for each case.

Loosely speaking as objects "survive" repeated garbage collections in the Young Generation they are migrated to the Tenured Generation. The Permanent Generation is a special case, it contains objects that are needed by the JVM that are not necessarily represented in your program such as objects that represent classes and methods.

Since the Young Generation will usually contain a lot of garbage in it is optimised for getting rid of a lot of unused objects at once. The Tenured Generation since it contain longer lived objects is optimised for speedy garbage collection without wasting a lot of memory.

With improvements in garbage collection technology the details have become pretty complex and vary depending on your JVM and how it has been configured. You should read the documentation for the specific JVM you are using if you need to know exactly what is happening.

That said there is a simple historical arrangement this is still useful at a conceptual level. Historically the Young Generation would be a copy collector and the Tenured Generation be a mark and sweep collector. A copy collector pays essentially no CPU cost for getting rid of garbage most of the cost in in maintaining live objects, the price of this efficiency is heavier memory usage. A mark and sweep collector pays some CPU cost for both live and and unused objects but utilizes memory more efficiently.

Tendayi Mawushe
what kind of objects are reside on perm generation ?
Thomman
I have clarified the answer with regard to the permanent generation. Basically the JVM needs some objects of it's own to manage your application These objects are typically not used directly in your application code. Objects in the Permanent Generation are never garbage collected hence the name.
Tendayi Mawushe
+1  A: 

Here's another excellent (though long) article on how to tune/size your GC parameters, which may help you understand even more:

http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

A very useful read if you're having GC issues and need to know how to read GC logs, or need to understand how your current GC collector works.

If you want to hook up remote monitoring of a running system to see realtime memory usage and GC runs check this tool out:

http://java.sun.com/performance/jvmstat/visualgc.html

simonlord