PermGen and Heap, Difference and their significanc

2019-03-09 21:37发布

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.

Explanation related to Java VM specification would be really helpful

Thanks Punith

5条回答
霸刀☆藐视天下
2楼-- · 2019-03-09 22:12

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.

查看更多
走好不送
3楼-- · 2019-03-09 22:13

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.

When any new object is constructed it goes to Eden space which is a part of Young Generation.

If object is still alive after some time it goes to tenured generation where long lived objects lie.

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.

查看更多
干净又极端
4楼-- · 2019-03-09 22:13

I was having the same doubt about the PermGen and other Heap memory parts. After doing some search, here what I finally concluded.

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.

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.

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.

Apart from objects and class structure, JVM code itself loads profiler agent code and data etc.

So basically, heap = object + class structure + JVM architecture.

References: Java Docs, Java GC Guide

查看更多
手持菜刀,她持情操
5楼-- · 2019-03-09 22:17

Good links are there in What does PermGen actually stand for?. Especially liked this blog

查看更多
\"骚年 ilove
6楼-- · 2019-03-09 22:27

I believe Permgen is memory area inside Heap memory only. It is created for special purpose like holding String.

All the object created does not get Permgen Memory It is only for special clasess like String in JDK 6 or below.

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.

查看更多
登录 后发表回答