HEAP MEMORY EXPLAINED
In my previous article ,I explained about JVM Memory architecture(link). In this article we will look into one part of that JVM Memory which all java programmers must understand. This will be a basic explaination of what Heap Memory is.
So what is HEAP MEMORY ?
Heap Memory is the part of JVM Memory where all the class instances are assigned memory.
That is whenever you create a object in your code that object is stored in heap memory.
Why understanding HEAP MEMORY is Important
If your code tries to use more heap memory than what is initially allocated as maximum heap memory for JVM then an out of memory exception is thrown which will result in unwanted shutdown of your jvm.
Heap Memory Allocation:-
Heap memory is allocated to the jvm when a jvm is created.
By default the maximum heap memory assigned to a jvm is 64 Mb .
The -server tag increases the default heap memory to 128 Mb.
-Xms defines the initial heap memory to be allocated to the jvm.
-Xmx defines the maximum heap memory to be allocated to the jvm.
Heap Memory Usage:
Heap memory consists of two type of objects
Live Objects : The objects which are currently being used by the jvm ,i.e., the object is within its scope.
Dead Objects: These are the objects which are now not in their scope and are of no more use to jvm.
These objects are removed from heap memory by garbage collector.
Conclusion:
Any java developer who are going to use their java application in production environment , they should consider how much heap should be provided , how their heap usage is distributed.
If there is any outofMemory error then where to look . I will soon write about how to analyze heap memory distribution.
Thanks and feel free to comment and ask for any doubt.
So what is HEAP MEMORY ?
Heap Memory is the part of JVM Memory where all the class instances are assigned memory.
That is whenever you create a object in your code that object is stored in heap memory.
Why understanding HEAP MEMORY is Important
If your code tries to use more heap memory than what is initially allocated as maximum heap memory for JVM then an out of memory exception is thrown which will result in unwanted shutdown of your jvm.
Heap Memory Allocation:-
Heap memory is allocated to the jvm when a jvm is created.
By default the maximum heap memory assigned to a jvm is 64 Mb .
The -server tag increases the default heap memory to 128 Mb.
-Xms defines the initial heap memory to be allocated to the jvm.
-Xmx defines the maximum heap memory to be allocated to the jvm.
Heap Memory Usage:
Heap memory consists of two type of objects
Live Objects : The objects which are currently being used by the jvm ,i.e., the object is within its scope.
Dead Objects: These are the objects which are now not in their scope and are of no more use to jvm.
These objects are removed from heap memory by garbage collector.
Conclusion:
Any java developer who are going to use their java application in production environment , they should consider how much heap should be provided , how their heap usage is distributed.
If there is any outofMemory error then where to look . I will soon write about how to analyze heap memory distribution.
Thanks and feel free to comment and ask for any doubt.
Comments
Post a Comment