JVM - Memory (The Heap)

1 - About

The JVM memory consists of the following segments:

  • Heap Memory, which is the storage for Java objects
  • Non-Heap Memory, which is used by Java to store loaded classes and other meta-data
  • JVM code itself, JVM internal structures, loaded profiler agent code and data, etc.

3 - Property

3.1 - JVM_ARGS

The environment variable JVM_ARGS is used to override JVM settings.

For example:

set JVM_ARGS="-Xms1024m -Xmx1024m -Dpropname=propvalue" 

3.2 - Property Name

3.2.1 - Heap

The heap memory is used to store Java Object.

The heap size may be configured with the following VM options when starting the JVM

-Xms<size> - to set the minimal/starting Java heap size
-Xmx<size> - to set the maximum Java heap size

By default, the maximum heap size is 64 Mb. If the application asks more than the maximum the JVM will throw the following exception: java.lang.OutOfMemoryError : Java Heap space.

The heap is managed by the garbage collector policy.

3.2.2 - Permanent generation

-XX:MaxPermSize (Maximum size of the permanent generation)


4 - Methods

5 - Example

java -Xms256m -Xmx2048m -XX:MaxPermSize=512m -jar myJar.jar


-Xms256m -Xmx2048m -XX:MaxPermSize=512m
-Xms128m -Xmx1024m -XX:MaxPermSize=256m
-Xms64m  -Xmx512m  -XX:MaxPermSize=128m

6 - Software

6.1 - Memory Analyzer (MAT)

Memory Analyzer (MAT)

The Eclipse Memory Analyzer is a fast and feature-rich Java heap analyzer that helps you find memory leaks and reduce memory consumption.

Use the Memory Analyzer to analyze productive heap dumps with hundreds of millions of objects, quickly calculate the retained sizes of objects, see who is preventing the Garbage Collector from collecting objects, run a report to automatically extract leak suspects.

6.2 - Query heap dump via SQL

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap