Java Memory Management for Java Virtual Machine(2023)
If you want to learn how jvm works internally and how many memory it's occupied at the time of run.when we compile our program and run then jvm occupied some memory for class members like ,data types,variables,functions,objects etc.
Java application communicates with jvm by using Runtime object.Runtime class present inside java.lang package.
Based on our requirement we can create Runtime object.as follows.
Java application communicates with jvm by using Runtime object.Runtime class present inside java.lang package.
Based on our requirement we can create Runtime object.as follows.
Runtime r=Runtime.getRunttime();
After creating Runtime class object we can call memory methods.
class Test
{
public static void main(String[] args)throws Exception
{
Runtime r=Runtime.getRuntime();
double mb=1024*1024;
System.out.println("MAx memory inside jvm:"+r.maxMemory());
System.out.println(" total memory inside jvm:"+r.totalMemory());
System.out.println("free memory is inside jvm:"+r.freeMemory());
}
}
output:
MAx memory inside jvm:1890582528
total memory inside jvm:128974848
free memory is inside jvm:127611672