问题描述
我对 Heap、Young、Tenured 和 Perm 一代感到困惑.
I'm confused with Heap,Young,Tenured and Perm generation.
谁能解释一下?
推荐答案
Java 垃圾收集器被称为Generational Garbage Collector.应用程序中的对象存在不同的时间长度,具体取决于它们的创建位置和使用方式.这里的关键见解是,对短期和长期对象使用不同的垃圾收集策略可以针对每种情况专门优化 GC.
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.
粗略地说,随着对象在年轻一代中存活"重复的垃圾回收,它们被迁移到老一代.永久生成是一种特殊情况,它包含 JVM 所需的对象,但不一定在程序中表示,例如表示类和方法的对象.
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.
由于年轻一代中通常会包含大量垃圾,因此针对一次摆脱大量未使用的对象进行了优化.Tenured Generation 因为它包含寿命更长的对象,所以针对快速垃圾收集进行了优化,而不会浪费大量内存.
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.
随着垃圾收集技术的改进,细节变得相当复杂,并且取决于您的 JVM 及其配置方式.如果您正在使用的特定 JVM,您应该阅读 文档你需要确切地知道发生了什么.
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.
也就是说,有一个简单的历史安排,这在概念层面上仍然有用.从历史上看,年轻一代是文案收集者 和 Tenured Generation 是 标记和扫描收集器.复制收集器基本上不需要 CPU 成本来清除垃圾,大部分成本是维护活动对象,这种效率的代价是更重的内存使用.标记和清除收集器会为活动对象和未使用对象支付一些 CPU 成本,但会更有效地利用内存.
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.
这篇关于Young , Tenured 和 Perm 一代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!