Friday, July 18, 2014

Java Heap Memoy and Permgen Space

Heap Memory

                It is the memory allocated from OS memory by the JVM. When new object in java created , jvm allocated it to heap memory. The object which are in use is called live objects and object which are not using is treated as garbage. To remove this garbage jvm performs garbage collection.

               Heap memory divided in to "young" and "old" generation. The objects which are initially created in young generation. This young portion is very active and garbage collection happens very frequently. So some of the objects will clear in this phase. The object which are surviving in GC will move to old generation. The old generation contains large long lasting objects which is survived from young GC. GC in this area is less frequent. The GC in young generation will not much impact but in old generation.

we will define heap memory in 2 values.

1. Max heap   -Xmx
2. Initial Heap / Min heap  -Xms

             There are some rules for choosing this values.There are 32 bit and 64 Bit systems. So in 32 bit system the maximum memory can use theoretically 4 GB. But in 64 bit it is unlimited because the addressing capability. So in 32 Bit system we can assign 1.4GB to 1.6 GB. ( Note: There are some exceptions in some operating systems).

We are defining heap memory mostly with JAVA_OPTS or can define in each application server's defined variables.

JAVA_OPTS="-Xms1024m -Xmx2048m"

Always use the correct megabyte values. 1024 X Mega byte you required.

Perm Gen Space | Permanent Generation

                Permanent Generation is used for storing class files. These class files  are mostly loading when application starts but some can load during application execution.

-XX:MaxPermSize=256m is the syntax for defining the Permgen space.

1/4 of Max Heap(Xmx) can be allocate as Permgen space.

For better calculation of memory for java it is always better to use some profiling tools like visual vm. In practical case mostly we will do -Xmx and -Xms as same .


No comments:

Post a Comment

Which operating system you like most?