[Fixed] Initial heap size set to a larger value than the maximum heap size

In this post, we will how to resolve initial heap size set to a larger value than the maximum heap size in java.

Problem: Initial heap size set to a larger value than the maximum heap size

This error is related to Xmx and Xms parameters in java and these parameters are used to provide heap memory of the JVM.

-Xms: This specifies initial heap size for JVM
-Xmx: This specifies maximum heap memory size for JVM

💻 Awesome Tech Resources:
  • Looking for ⚒️ tech jobs? Go to our job portal.
  • Looking for tech events? Go to tech events 🗓️ Calendar.️

This simply means JVM will start with mimimum Xms amount of memory and can take up to xmx amount of memory.

Let’s reproduce this error now.

We will take a simple example about how to print arraylist in java.

Let’s compile and run the code.

C:\Users\Arpit\Desktop\javaPrograms>javac PrintArrayListMain.java

C:\Users\Arpit\Desktop\javaPrograms>java -Xms1024m -Xmx512m org/arpit/java2blog/PrintArrayListMain
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size

As you can see, we got the error Initial heap size set to a larger value than the maximum heap size.

C:\Users\Arpit\Desktop\javaPrograms>java -Xms2g -Xmx1g org/arpit/java2blog/PrintArrayListMain
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size

Solution 1: Initial heap size set to a larger value than the maximum heap size

We are getting this error because Xms(minimum heap size) is greater than Xmx(maximum heap size).

Xms should always be lesser than Xmx to run java program correctly.

Let’s change -Xms to 512m and -Xmx to 1024m now.

C:\Users\Arpit\Desktop\javaPrograms>java -Xms512m -Xmx1024m org/arpit/java2blog/PrintArrayListMain
[India, China, Bhutan]

As you can see, error is resolved now and we got expected output.

That’s all about initial heap size set to a larger value than the maximum heap size in java.

Solution 2: Change Xms value in vmoptions file for intellij

If you are getting this error in intellij, then you should check Xms value in vmoptions file.

On windows:
You should be able to find the file on windows at following path:

On Mac:
You should be able to find the file on mac at following path:

On linux:
You should be able to find the file on linux at following path:

You should change version based on your intellij version in above paths.

Check the value of Xms in idea64.vmoptions file and if it is greater than Xmx or not. If it is greater than Xmx, then we should fix it.

Here is content of idea64.exe.vmoptions file.

That’s all about how to fix Initial heap size set to a larger value than the maximum heap size in java.

Related Posts

  • 15 September

    What are Xmx and Xms parameters in java

    In this post, we will see about Xms and Xmx parameter in java. -Xmx specifies maximum memory size for Java virtual machine (JVM), while -Xms specifies the initial memory size. It means JVM will be started with Xms amount of memory and JVM will be able to use maximum of JVM amount of memory. 💻 […]

  • 16 July

    Garbage Collection in java

    In this post, we will see about Garbage Collection in java. I will try to explain with the help of diagrams and examples rather than theory. JVM Memory is divided into three parts 💻 Awesome Tech Resources: Looking for ⚒️ tech jobs? Go to our job portal. Looking for tech events? Go to tech events […]

  • 19 August

    Java virtual Machine(JVM) and its architecture

    In this article, you will know about java virtual machine which made Java as more popular. We all know that Java applications can be write once and run many times anywhere. This is possible with only JVM. Because Java was designed to run on a virtual machine. A virtual machine is software. This JVM will […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.