Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

java - Young , Tenured and Perm generation

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

Could anyone please explain?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 to 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, for example objects that represent classes and methods.

Since the Young Generation will usually contain a lot of garbage in it, it is optimised for getting rid of a lot of unused objects at once. The Tenured Generation since it contains 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 is 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 unused objects but utilizes memory more efficiently.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...