Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between class area and heap

Tags:

java

memory

jvm

The JVM allocates these areas in memory: Class(Method) Area, Heap, Stack, Program counter Register, Native method stack.

I know that heap is used to store objects and stack is used to store local variables and partial results. According to definition, Class(Method) Area stores per-class structures such as the runtime constant pool, field and method data, the code for methods. But I really don't understand the difference.

Can anyone please explain the difference between Class area and Heap?

like image 638
trailblazer Avatar asked Oct 12 '13 22:10

trailblazer


1 Answers

Java 6 stores all the constant pool and Class information in the Perm Gen

Java 7 only stores the class information in the Perm Gen. The String literal pool is on the heap.

Java 8 has no Perm Gen. The literal pools and class information are on the heap.

You have explained the difference. Class structures like methods are stored in perm gen. The data in each instance is stored in the heap.

They were separated as these types of data have very different lifecycles e.g. Objects are typically short lived and classes are typically very long lived.

AFAIK They are removing it because too many developers found it confusing.

like image 197
Peter Lawrey Avatar answered Sep 21 '22 02:09

Peter Lawrey