[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

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.

Was this post helpful?

Comments

Leave a Reply

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