Invalid Initial And Maximum Heap Size In JVM - How To Fix

Javarevisited

Learn Java, Programming, Spring, Hibernate throw tutorials, examples, and interview questions

Topics and Categories

  • core java
  • spring
  • hibernate
  • collections
  • multithreading
  • design patterns
  • interview questions
  • coding
  • data structure
  • OOP
  • java 8
  • books
  • About Me
  • Java Certifications
  • JDBC
  • jsp-servlet
  • JSON
  • SQL
  • Linux
  • Courses
  • online resources
  • jvm-internals
  • REST
  • Eclipse
  • jQuery
  • Java IO
  • Java XML

Friday, July 30, 2021

Invalid initial and maximum heap size in JVM - How to Fix I was getting "Invalid initial heap size: -Xms=1024M" while starting JVM and even after changing the maximum heap size from 1024 to 512M it keeps crashing by telling "Invalid initial heap size: -Xms=512m, Could not create the Java virtual machine". I check almost everything starting from checking how much physical memory my machine has to any typo in JVM parameters, only to find out that instead of M, I had put MB there. Java accepts both the small case and the capital case for Kilo, Mega, and Gigs. you can use m or M, g or G, etc but never used MB, GB, or KB. A similar problem can occur with the maximum heap size specified by -Xmx. Also from Java 6 update 18, there is a change in default heap size in JVM.

Invalid initial and maximum heap size in JVM

Here is a list of common errors while specifying maximum and minimum heap size in Java : java -Xmx4056M -Xms4056M HelloWorld Issue:Error occurred during initialization of VM , The size of the object heap + VM data exceeds the maximum representable size Cause: the value of either -Xms or -Xmx is higher than or close to the size of physical memory, as my machine has 4GB memory. java -Xmx1056M -Xms2056M HelloWorld Issue:Error occurred during initialization of VM , Incompatible minimum, and maximum heap sizes specified Cause: the value of -Xms is higher than -Xmx java -Xms2056M HelloWorld Issue: Error occurred during initialization of VM , Could not reserve enough space for object heap Cause: Only -Xms was provided and -Xmx was not provided. you will also get this error if you have a typo and instead of -Xmx you have specified -Xms two times, happened to my friend last time. Command: java -Xms1024 M -Xmx1024M HelloWorld Issue: Error occurred during initialization of VM , Too small initial heap Cause: If you had space between 1024 and M then JVM assumes the size of -Xms as 1024 bytes only and prints an error that it's too small for JVM to start.

Invalid heap size

Invalid initial and maximum heap size in JVMAnother scenario when the "invalid heap size" issue comes while restarting JVM is when you configure 64 bit JVM to accept the memory of more than 4GB but it's running on a 32-bit data model. This "invalid heap size" occurs particularly in the Solaris box where J2SE installation contains both 32 bit and 64-bit J2SE implementation. On other environments like Windows and Linux, 32 bit and 64 bit JVM are installed separately. 64 bit JVM installed on Solaris machines runs with a 32-bit model if you don't specify either -d32 or -d64, which won't accept a Maximum heap size of 4GB, hence "invalid heap size". You can resolve this issue by running Solaris JVM with option -d64. -d64 command-line option allows JVM to use a 64-bit data model if available. public class HelloWorld{ public static void main(String args[]){ System.out.println("HelloWorld to Java"); } } $ test@nykdev32:~ java -version java version "1.6.0_14" Java(TM) SE Runtime Environment (build 1.6.0_14-b08) Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode) $ test@nykdev32:~ java -Xmx4096M HelloWorld Invalid maximum heap size: -Xmx4096M The specified size exceeds the maximum representable size. Could not create the Java virtual machine. $ test@nykdev32:~ java -d64 -Xmx4096M HelloWorld HelloWorld to Java If you run the Java program from the command line then you will also get a message that say Could not create the Java virtual machine with each invalid heap error but if you run your program from Eclipse you will not get the message "Could not create the Java virtual machine", instead, you will just see an error message in the console. Regarding default heap size in Java, from Java 6 update 18 there are significant changes in how JVM calculates default heap size in 32 and 64-bit machines and on client and server JVM mode: 1) Initial heap space and maximum heap space is larger for improved performance. 2) The default maximum heap space is 1/2 of the physical memory of size up to 192 bytes and 1/4th of physical memory for a size up to 1G. So for a 1G machine maximum heap size is 256MB 2.maximum heap size will not be used until the program creates enough objects to fill the initial heap space which will be much lesser but at least 8 MB or 1/64th part of Physical memory up to 1G. 3) For Server Java virtual machine default maximum heap space is 1G for 4GB of physical memory on a 32 bit JVM. for 64 bit JVM it's 32G for physical memory of 128GB. Other Java tutorials you may find useful How Garbage collection works in Java How ClassLoader works in Java 10 Garbage Collection Interview question Answer How to remote debug Java program in Eclipse How to increase heap size in Maven and ANT script

6 comments :

Anonymous said...

Hello, I am getting following error, while starting a core Java based Server in a shared Solaris host "Error occurred during initialization of VMCould not reserve enough space for object heap" , Program was running fine few days ago, but when I am restarting it now, it's giving me this error. There is no change in JVM arguments passed to program, I also tried with different heap size (4GB, 2GB, 500MB) , but still same error, please help

April 16, 2013 at 7:36 PM Anonymous said...

Thanks for this, this saved my day. I am getting below error in Maven, while running mvn install while building a Java project on Eclipse IDE :Error occurred during initialization of VMCould not reserve enough space for object heapError: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Program will exit.Later I realized that I was using JDK 1.7 32-bit virtual machine and configuring Maven's surefire plugin, which is used to run all JUnit test cases with following JVM memory arguments :-Xms800m -Xmx800m -XX:MaxPermSize=500mSince this configuration was actually for 64-bit JVM, it was throwing Invalid Heap Size error. There was two ways to fix that, either moving to 64-bit JDK or reducing memory size to half e.g. -Xms400m -Xmx400m -XX:MaxPermSize=200mFor me second solution works fine. Thanks

October 4, 2013 at 2:59 AM Anonymous said...

I am getting following error while running my maven build :Error occurred during initialization of VMIncompatible minimum and maximum heap sizes specifiedPlease help

October 6, 2013 at 7:41 PM Anonymous said...

The particular error listed at the top ("Invalid initial heap size: -Xms=1024M") is caused by having the equals sign, so changing it to just "-Xms1024M" should take care of it, as I just found out from a misconfiguration of my own.

February 19, 2014 at 12:08 PM Anonymous said...

I am using JDK8, and trying to run a Junit from my eclipse. and I am getting the error as "Invalid Initial heap size: -Xms8192mThe specified size exceeds the maximum representable size"

October 3, 2025 at 8:19 AM javin paul said...

Hello @anonymous, just check if you are using 32-bit JVM on which max heap size is 4GB since you are giving 8GB its giving the error. Most likely you don't need that much heap so you can reduce it to 1GB and try again and if you do need, switch to 64-bit JVM

October 4, 2025 at 9:55 PM

Post a Comment

Newer Post Older Post Home Subscribe to: Post Comments ( Atom )

Best System Design and Coding Interview Resources

System Design & Interview Prep

  • ByteByteGo Lifetime Plan (50% OFF)
  • Codemia Lifetime Plan (60% OFF)
  • Exponent Annual Plan (70% OFF)
  • Educative Premium Plus (55% OFF)
  • DesignGurus All Course Bundle (55% OFF)
  • Everything Java Interview Bundle (50% OFF)
  • 101 Blockchain (50% OFF)
  • Vlad Mihalcea's High Performance Bundle (50% OFF)
  • Javarevisited Substack Subscription (50% OFF)
  • Head First Software Architecture (Book)

Best Online Learning Resources and Platforms

  • Coursera Plus (40% OFF)
  • Datacamp Black Friday Sale (50% OFF)
  • AlgoMonster Lifetime Plan (50% OFF)
  • Udemy Black Friday Sale (80% OFF)
  • Baeldung Black Friday Sale (33% OFF)
  • LabEx Black Friday Sale (50% OFF)
  • Codecademy Black Friday Sale (60% OFF)
  • Udacity Black Friday Sale (50% OFF)
  • ZTM Academy Sale (66% OFF)
  • Frontend Masters Black Friday Deal
  • Whizlabs Black Friday Deal (70% OFF)

Search This Blog

Preparing for Java and Spring Boot Interview?

  • Join My Newsletter .. Its FREE

My Books

  • Everything Bundle (Java + Spring Boot + SQL Interview) for a discount
  • Grokking the Java Interview
  • Grokking the Spring Boot Interview
  • Spring Framework Practice Questions
  • Grokking the SQL Interview
  • Grokking the Java Interview Part 2
  • Grokking the Java SE 17 Developer Certification (1Z0-829 Exam)

My Courses

  • Spring Professional Certification Practice Test
  • Java SE 11 Certification Practice Test
  • Azure Fundamentals AZ-900 Practice Test
  • Java EE Developer Exam Practice Test
  • Java Foundations 1Z0-811 Exam Practice Test
  • AWS Cloud Practitioner CLF-C02 Exam Practice Test
  • Java SE 17 1Z0-829 Exam Practice Test
  • Azure AI-900 Exam Practice Test
  • 1Z0-829 Java Certification Topic wise Practice Test

My Newsletter articles

  • How to grow financially as Software Engineer?
  • Difference between Microservices and Monolithic Architecture
  • What is Rate Limiter? How does it work
  • Difference between @Component vs @Bean annotations in Spring Framework?
  • Top 10 Software Design Concepts Every Developer should know
  • How does SSO Single Sign On Authentication Works?

Interview Questions

  • core java interview question (183)
  • interview questions (110)
  • data structure and algorithm (92)
  • Coding Interview Question (86)
  • spring interview questions (52)
  • design patterns (48)
  • object oriented programming (42)
  • SQL Interview Questions (37)
  • thread interview questions (30)
  • collections interview questions (26)
  • database interview questions (16)
  • servlet interview questions (15)
  • hibernate interview questions (11)
  • Programming interview question (6)

Java Tutorials

  • FIX protocol tutorial (16)
  • JDBC (35)
  • Java Certification OCPJP SCJP (33)
  • Java JSON tutorial (23)
  • Java Programming Tutorials (21)
  • Java multithreading Tutorials (64)
  • Java xml tutorial (16)
  • date and time tutorial (27)
  • java IO tutorial (30)
  • java collection tutorial (94)
  • jsp-servlet (37)
  • online resources (218)

Get New Blog Posts on Your Email

Get new posts by email:
Subscribe

Followers

Categories

  • courses (312)
  • SQL (78)
  • linux (54)
  • database (52)
  • Eclipse (38)
  • REST (34)
  • Java Certification OCPJP SCJP (33)
  • JVM Internals (27)
  • JQuery (26)
  • Testing (24)
  • Maven (16)
  • general (16)

Blog Archive

  • ▼  2021 (251)
    • ▼  July (101)
      • How to Solve UnrecognizedPropertyException: Unreco...
      • java.lang.ClassNotFoundException: org.postgresql.D...
      • Why multiple inheritances are not supported in Java
      • How to create HTTP Server in Java - ServerSocket E...
      • How to do GROUP BY in Java 8? Collectors.groupingB...
      • How SSL, HTTPS and Certificates Works in Java web ...
      • When to Make a Method Static in Java? Example
      • Different Types of JDBC Drivers in Java - Quick Ov...
      • Difference between ClassNotFoundException vs NoCla...
      • Why Enum Singleton are better in Java? Examples
      • 5 Coding Tips for Improving Performance of Java ap...
      • Difference between repaint and revalidate method i...
      • When a class is loaded and initialized in JVM - Ja...
      • Java ArrayList and HashMap Performance Improvement...
      • Is Swing Thread Safe in Java? Answer
      • Invalid initial and maximum heap size in JVM - How...
      • How to Close Java Program or Swing Application wit...
      • InvokeLater and InvokeAndWait in Java Swing (an ex...
      • How to Use Break, Continue, and Label in Loop in ...
      • 10 Examples of HotSpot JVM Options in Java
      • Difference between Sun (Oracle) JVM and IBM JVM?
      • How to Generate MD5 checksum for Files in Java? Ex...
      • How to find CPU and Memory used by Java process in...
      • How ClassLoader Works in Java? Example
      • How to use Comparator and Comparable in Java? With...
      • 10 Interview Questions on Java Generics for Progra...
      • What is -XX:+UseCompressedOops in 64 bit JVM? Example
      • Top 10 Garbage Collection Interview Questions and ...
      • What is Class File and Byte Code in Java? Example
      • Top 10 Java Swing Interview Questions Answers aske...
      • Difference between JVM, JIR, JRE, and JDK in Java?...
      • How to increase Heap memory of Apache Tomcat Serve...
      • How many characters allowed on VARCHAR(n) columns ...
      • What is bounded and unbounded wildcards in Generic...
      • Difference between Right shift and Unsigned right ...
      • What is the maximum Heap Size of 32 bit or 64-bit ...
      • How to Create JUnit Tests in Eclipse and NetBeans ...
      • How to add and substract days in current date in J...
      • 10 JDK 7 Features to Revisit, Before You Welcome J...
      • 7 Examples to Read File into a Byte Array in Java
      • How to Add Leading Zeros to Integers in Java ? Str...
      • How to Compare Two Enum in Java? Equals vs == vs C...
      • How to disable JUnit Test - @Ignore annotation Exa...
      • The Ultimate Guide of Generics in Java - Examples
      • Difference between trunk, tags and branches in SVN...
      • How to convert double to int in Java? Example
      • Does making all fields Final makes the class Immut...
      • Top 10 Tips on Logging in Java - Tutorial
      • How to Setup Java Remote Debugging in Eclipse - St...
      • Difference Between java and javaw Commands from JDK
      • Java Program to connect Oracle Database with Examp...
      • Difference between ValidatorForm vs ValidatorActio...
      • 10 points about Java Heap Space or Java Heap Memory
      • How to Measure Elapsed Execution Time in Java - Sp...
      • How to Invoke Method by Name in Java Dynamically U...
      • Difference Between java.util.Date and java.sql.Dat...
      • How to convert Local Time to GMT in Java - Example...
      • What is rt.jar in Java/JDK/JRE? Why it’s Important?
      • Java PropertyUtils Example - getting and setting p...
      • What is Effectively Final variable of Java 8? Example
      • Top 10 JSP Interview Questions Answers for Java Pr...
      • 5 Difference between Application Server and Web Se...
      • Display tag Pagination, Sorting Example in JSP and...
      • Bitwise and BitShift Operators in Java - AND, OR, ...
      • How to Install JDK on Windows - Java Programming...
      • How to format Date and Time in SQL Server and Syba...
      • What is JSESSIONID in Java Web application - JSP S...
      • How to Export HTML to PDF, CSV, and Excel using Di...
      • How to Configure HTTPS (SSL) in Tomcat 6 and 7 Jav...
      • JDBC - java.lang.ClassNotFoundException: com.mysql...
      • File Upload Example in Java using Servlet, JSP and...
      • How to Split String in JSP? JSTL forTokens Tag Exa...
      • How to test Exception thrown by a Java Method in J...
      • 10 examples of displaytag in JSP, Struts and Spring
      • How to change Tomcat default port 8080? Example Steps
      • How to define Error page in Java Web Application -...
      • How to Disable submit button in HTML JavaScript? M...
      • JSTL foreach tag example in JSP - looping ArrayList
      • JSP - How to check if ArrayList is Empty using JST...
      • Difference between Servlet and JSP? Example
      • How to get ServletContext in Servlet, JSP, Action ...
      • How to loop over HashMap in JSP using JSTL? Example
      • Difference Between ON HOLD and ON ICE Jobs in Auto...
      • How to find file and directory size in Unix with E...
      • Top 10 basic networking commands in linux/unix - E...
      • 10 Examples of CUT command in UNIX and Linux
      • Linux and UNIX Command Tutorial, Tips and Examples...
      • 10 xargs command example in Linux - Unix tutorial
      • 10 Examples of Date Command in Linux and UNIX
      • 5 Example of kill command in UNIX and Linux
      • 5 Articles to Learn about Shellshock Bash Bug
      • How to find IP Address from hostname in Windows Li...
      • 10 Examples of tar command in UNIX and Linux
      • List of special bash parameter used in Unix or Li...
      • 2 Ways to find Tomcat and Java Version in Linux an...
      • How to read a text file using Scanner in Java? Exa...
      • 4 Free OCAJP 7 and OCPJP7 Mock Exams - Online Prac...
      • Tibco Tutorials for Beginner to Learn RV and EMS
      • Difference between FIX 4.2 vs FIX 4.4 Protocol? An...
      • Basics of FIX protocol and FIX Engine - Examples

Contributors

  • SimpleJava
  • javin paul

Popular Posts

  • Top 5 Websites to Learn SQL Online for FREE - Best of Lot SQL is one of the most important skills for any programmer be it a Java , C++ , Python , JavaScript , or Ruby developer. Almost 95% of the J...
  • How to create HTTP Server in Java - ServerSocket Example Java has very good networking support, allows you to write client-server applications by using TCP Sockets. In this tutorial, we will learn...
  • The 2025 Java Developer RoadMap [UPDATED] Hello guys, I have been sharing a lot of roadmaps to become a Web developer , DevOps engineer , and recently React.js developer . One of th...
  • Top 5 Udemy + Pluralsight Courses to Learn Vue.js in 2025 - Best of Lot Hello frontend and full-stack developers, if you want to use Vue.js for your next project and looking to learn Vue.js online and looking for...
  • Top 10 Java, Spring, and Hibernate Books for Experienced Java Web Developers in 2025 Hello guys, If you are thinking that you have read all the essential books on Java and don't have anything new to read, then hang on. J...
  • DesignGurus.io or Bugfree.ai? Which is Better Place to Prepare for System Design Interview in 2026? Hello guys, preparing for coding interviews in 2026 is much more competitive than ever. The tech market is flooded with more qualified can...
  • 3 ways to solve java.lang.NoClassDefFoundError in Java J2EE I know how frustrating is to see "Exception in thread "main" java.lang.NoClassDefFoundError" while running your Java ...
  • Top 20 Books Every Java Programmers Should Read [UPDATED] Hello guys, Happy New Year. We are already in New Year and while I am busy making my goals , I am also looking back on what I have done in ...
  • Top 5 Courses to Learn Eclipse IDE for Java Programmers in 2025 - Best of Lot Hello guys, If you are in Java development, you may know that Eclipse is one of the most popular IDEs for Java development and millions of ...
  • Top 10 Big Data Tutorials, Books, and Courses for Java Developers in 2025 - Best of Lot Hello Java developers, if you are looking to learn Big Data and Hadoop this year and looking for excellent books, courses, and tutorials to...

Subscribe To

Posts Atom Posts Comments Atom Comments

Pages

  • Privacy Policy
  • Terms & Conditions
Copyright by Javin Paul 2010-2025. Powered by Blogger.

Từ khóa » G Xmx