This site javatpoint is very useful for programming languages like JAVA,PYTHON,C,C++, Data Structures etc.Java learning Concept also provides technical materials , which are related to latest technologies. We provides very easy lectures to our viewers from beginning to advance level.We focus logical content instead of theoretical content.

Thursday, 9 August 2018

Heap memory in java

STATISTICS  OF HEAP MEMORY AREA

In the given example you will see int the  jvm how the memory area work's .when our class file load in the method area then jvm will creates a class, object into the heap memory area .so jvm also occupy some memory to run our class file.
class Heap
{
public static void main(String[] args)
{
Runtime r=Runtime.getRuntime();
long mb=1024*1024;
System.out.println("max memory of heap are :"+r.maxMemory());
System.out.println("total memory of heap are :"+r.totalMemory());
System.out.println("free memory of heap are :"+r.freeMemory());
}
}



output:
C:\java programs>java Heap
max memory of heap are :2126512128
total memory of heap are :134217728
free memory of heap are :132286136


In the above example clearly seen, required memory areas inside the heap memory area in jvm.
here, max memory ,total memory and free memory required memory areas in the heap.


Note:java application can communicate's internally with the jvm through the Runtime class object.and we can create the object of Runtime,

Based our requirement we can increase or decrease the size of the memory areas inside the heap memory area.

  • If you want to increase the max memory area ,then you have to use this java command explicitly .
java -Xmx  class Name.

ex:
C:\java programs>java -Xmx100m HeapDemo
max memory of heap are :104857600
total memory of heap are :104857600
free memory of heap are :102925976
  • If you want to increase total memory area then you have to follow this java command
 java -Xms  class Name.
ex:

C:\java programs>java -Xms70m HeapDemo
max memory of heap are :2126512128
total memory of heap are :73400320
free memory of heap are :71468344
Adbox