java PermGen 和 Heap,区别及其意义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11009795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PermGen and Heap, Difference and their significance
提问by Punith Raj
Friends,
朋友们,
Can you please give me significance, difference and uses for Heap and PermGen. Also it would be good to know what class are loaded in them respectively.
你能告诉我 Heap 和 PermGen 的意义、区别和用途吗?此外,最好知道分别加载了哪些类。
Explanation related to Java VM specification would be really helpful
与 Java VM 规范相关的说明会非常有帮助
Thanks Punith
感谢普尼斯
回答by amicngh
Memory(Heap) is managed in generations, or memory pools holding objects of different ages. Garbage collection occurs in each generation when the generation fills up. Objects are allocated in a generation for younger objects or the young generation
, and because of infant mortality most objects die there.
内存(堆)是按代管理的,或者说内存池包含不同年龄的对象。当代填满时,垃圾收集在每一代中发生。对象在一代中分配给更年轻的对象或young generation
,并且由于婴儿死亡率,大多数对象都死在那里。
When any new object is constructed it goes to Eden space which is a part of Young Generation
.
当构建任何新对象时,它会进入作为 的一部分的伊甸园空间Young Generation
。
If object is still alive after some time it goes to tenured generation
where long lived objects lie.
如果对象在一段时间后仍然存在,则它会转到tenured generation
长期存在的对象所在的位置。
If object is supposed to live until over process exist then object is moved to Perm Generation
.Java classes
are stored in the permanent generation.
如果对象应该一直存在直到进程存在,那么对象将被移动到Perm Generation
. Java classes
存储在永久代中。
回答by bobby
Good links are there in What does PermGen actually stand for?. Especially liked this blog
良好的联系是否有什么PermGen的真正代表什么?. 特别喜欢这个博客
回答by aks
I was having the same doubt about the PermGen and other Heap memory parts. After doing some search, here what I finally concluded.
我对 PermGen 和其他堆内存部分也有同样的疑问。经过一番搜索,我终于得出了结论。
Java HotSpot VM needs memory which it gets from the operating system, this memory is termed as Heap memory. Now heap memory as famously known to store the objects and holds other important things as well.
Java HotSpot VM 需要从操作系统获取的内存,这种内存称为堆内存。现在众所周知的堆内存可以存储对象并保存其他重要的东西。
Short live span Java objects are stored in the young generation and if those objects are still needed for further execution then, it is shifted to the tenure/old generation. And depending upon the type of Generation Garbage Collector, memory is cleaned.
短寿命 Java 对象存储在年轻代中,如果这些对象仍需要进一步执行,则将其转移到任期/年老代。并且根据代垃圾收集器的类型,清理内存。
What about the Permanent Generation (PermGen)? Java HotSpot VM loads the classes/class structure in the PermGen which is used by JVM to store loaded classes and other meta-data. PermGen is not used to store objects.
永久代 (PermGen) 怎么样?Java HotSpot VM 在 PermGen 中加载类/类结构,JVM 使用它来存储加载的类和其他元数据。PermGen 不用于存储对象。
Apart from objects and class structure, JVM code itself loads profiler agent code and data etc.
除了对象和类结构之外,JVM 代码本身还加载分析器代理代码和数据等。
So basically, heap = object + class structure + JVM architecture.
所以基本上,堆=对象+类结构+JVM架构。
References: Java Docs, Java GC Guide
参考资料: Java Docs、 Java GC 指南
回答by Ed Morales
Well i'm no expert, but the PermGem memory resides within the Heap, since its like a special place where all the classes are loaded at runtime. So if you have too many classes, the PermGem throws an OutOfMemoryException. And well the heap stores the objects you instanciate within your java code, where the GC collects the objects that are not referenced by any variable in a running thread in the stack.
好吧,我不是专家,但 PermGem 内存驻留在堆中,因为它就像一个特殊的地方,所有类都在运行时加载。所以如果你有太多的类,PermGem 会抛出一个 OutOfMemoryException。并且堆很好地存储了您在 Java 代码中实例化的对象,GC 在其中收集堆栈中正在运行的线程中没有被任何变量引用的对象。
回答by kuladeep patil
I believe Permgen is memory area inside Heap memory only. It is created for special purpose like holding String.
我相信 Permgen 只是堆内存中的内存区域。它是为特殊目的而创建的,例如持有 String。
All the object created does not get Permgen Memory It is only for special clasess like String in JDK 6 or below.
所有创建的对象都不会获得 Permgen 内存,它仅适用于 JDK 6 或更低版本中的 String 等特殊类。
In modern JDK versions like 8 and above, Pergen is not found however new memory like Non Heap and other various cache memories are introduced.
在现代 JDK 版本(如 8 及更高版本)中,未找到 Pergen,但引入了非堆和其他各种缓存内存等新内存。