The flag Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms specifies the initial memory allocation pool.

This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. For example, starting a JVM like below will start it with 256 MB of memory and will allow the process to use up to 2048 MB of memory:

java -Xms256m -Xmx2048m

The memory flag can also be specified in different sizes, such as kilobytes, megabytes, and so on.

-Xmx1024k
-Xmx512m
-Xmx8g

The Xms flag has no default value, and Xmx typically has a default value of 256 MB. A common use for these flags is when you encounter a java.lang.OutOfMemoryError.

When using these settings, keep in mind that these settings are for the JVM's heap, and that the JVM can and will use more memory than just the size allocated to the heap. From Oracle's documentation:

Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures.

Answer from hexacyanide on Stack Overflow
Top answer
1 of 5
1938

The flag Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms specifies the initial memory allocation pool.

This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. For example, starting a JVM like below will start it with 256 MB of memory and will allow the process to use up to 2048 MB of memory:

java -Xms256m -Xmx2048m

The memory flag can also be specified in different sizes, such as kilobytes, megabytes, and so on.

-Xmx1024k
-Xmx512m
-Xmx8g

The Xms flag has no default value, and Xmx typically has a default value of 256 MB. A common use for these flags is when you encounter a java.lang.OutOfMemoryError.

When using these settings, keep in mind that these settings are for the JVM's heap, and that the JVM can and will use more memory than just the size allocated to the heap. From Oracle's documentation:

Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures.

2 of 5
425

Run the command java -X and you will get a list of all -X options:

C:\Users\Admin>java -X
-Xmixed           mixed mode execution (default)
-Xint             interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
                      set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
                      append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
                      prepend in front of bootstrap class path
-Xdiag            show additional diagnostic messages
-Xnoclassgc       disable class garbage collection
-Xincgc           enable incremental garbage collection
-Xloggc:<file>    log GC status to a file with time stamps
-Xbatch           disable background compilation
-Xms<size>        set initial Java heap size.........................
-Xmx<size>        set maximum Java heap size.........................
-Xss<size>        set java thread stack size
-Xprof            output cpu profiling data
-Xfuture          enable strictest checks, anticipating future default
-Xrs              reduce use of OS signals by Java/VM (see documentation)
-Xcheck:jni       perform additional checks for JNI functions
-Xshare:off       do not attempt to use shared class data
-Xshare:auto      use shared class data if possible (default)
-Xshare:on        require using shared class data, otherwise fail.
-XshowSettings    show all settings and continue
-XshowSettings:all         show all settings and continue
-XshowSettings:vm          show all vm related settings and continue
-XshowSettings:properties  show all property settings and continue
-XshowSettings:locale      show all locale related settings and continue

The -X options are non-standard and subject to change without notice.

I hope this will help you understand Xms, Xmx as well as many other things that matters the most. :)

🌐
Heaphero
blog.heaphero.io › home › sizing your heap correctly: understanding -xms and -xmx
-Xmx and -Xms: The Complete Guide to Java Heap Size
May 25, 2026 - In this article, we’ll cover what ... -Xmx flag sets the maximum heap size the JVM is allowed to use. Example: java -Xmx2g MyApp limits the heap to 2 GB....
Discussions

What do xmx and xms stand for?
-X is the prefix of non-standard general purpose options ( source ). mx is maximum, ms is minimum size. Just that. More on reddit.com
🌐 r/java
9
32
May 3, 2024
What is xmx and xms?
These values can be set when starting a Java application from the command line. Here’s an example of how to set both: ... Initial Setting: It's often recommended to set the initial heap size (Xms) and the maximum heap size (Xmx) to the same value. More on designgurus.io
🌐 designgurus.io
1
13
June 25, 2024
VS Code for Java: good or bad?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/java
113
53
July 18, 2023
Best Java extension on VS code?
IntelliJ 😉 More on reddit.com
🌐 r/java
35
27
October 28, 2024
🌐
IBM
ibm.com › docs › en › sdk-java-technology › 8
-Xms / -Xmx - IBM Documentation
January 22, 2026 - The Oracle® HotSpot™ option -Xms sets the initial or the minimum Java™ heap size, and the -Xmx HotSpot option sets the maximum heap size.
🌐
Sentry
sentry.io › sentry answers › java › understanding the java virtual machine's -xms and -xmx parameters
Understanding the Java Virtual Machine's -Xms and -Xmx parameters | Sentry
April 15, 2024 - So, for example, -Xmx1g will set the maximum heap size to 1 gigabyte. When both of these example parameter values are used together, i.e. -Xms256m -Xmx1g, the size of the heap will initially be 256 megabytes but will be allowed to grow to 1 ...
🌐
Mkyong
mkyong.com › home › java › java – what is -xms and -xmx parameter?
Java - what is -Xms and -Xmx parameter? - Mkyong.com
May 9, 2019 - # Start with 256MB of memory, and allow the Java process to use up to 4G (4096MB) of memory. java -Xms256m -Xmx4g
Top answer
1 of 1
13
In Java, Xmx and Xms are flags used to define the maximum and initial heap size for the Java Virtual Machine (JVM). They are critical parameters for controlling the memory usage of applications running on the JVM, which can directly affect the performance and stability of the applications. Xms (Initial Heap Size) Flag: -Xms Purpose: This flag sets the initial memory allocation for the JVM heap at startup. Impact: Setting this value tells the JVM how much memory to allocate initially for the heap when the Java application starts. If this value is set too low, the JVM may need to resize the heap multiple times as the application starts up and more objects are created, which can lead to increased garbage collection (GC) activity and reduced performance. On the other hand, setting it too high could waste memory if the application doesn't need it, especially on systems where resources are limited. Xmx (Maximum Heap Size) Flag: -Xmx Purpose: This flag sets the maximum memory allocation for the JVM heap. Impact: The Xmx setting determines the maximum amount of memory that the JVM is allowed to allocate for the heap. This is the maximum limit on the memory the JVM can use for dynamically allocated objects and data. Setting a proper Xmx value is crucial because if the heap grows to this limit and the garbage collector cannot reclaim enough memory, it could lead to an OutOfMemoryError. Conversely, setting this value too high can also tie up memory unnecessarily, which could be used by other applications or processes.
Find elsewhere
🌐
Educative
educative.io › answers › xms-and-xmx-java
xmx and xms Java
xmx and xms are JVM, Java Virtual Machine, command-line options/flags that are used by programmers to manipulate the heap size used by JVM.
🌐
Oracle
docs.oracle.com › cd › E13150_01 › jrockit_jvm › jrockit › jrdocs › refman › optionX.html
-X Command-line Options
The Java heap can never grow larger than -Xmx. Also, the -Xms value can be used as “minimum heap size” to set a fixed heap size by setting -Xms = -Xmx when, for example, you want to run benchmark tests.
🌐
Alvin Alexander
alvinalexander.com › blog › post › java › java-xmx-xms-memory-heap-size-control
How to control Java heap size (memory) allocation (xmx, xms) | alvinalexander.com
January 31, 2026 - Use -Xmx to specify the maximum ... or -Xmx1G // 1 gigabyte (maximum memory) A complete java command looks like this: java -Xmx64m -Xmx2G -classpath ".:${THE_CLASSPATH}" ${PROGRAM_NAME} See the rest of this article for more details....
🌐
Substack
roliagrawal.substack.com › roli’s substack › java: xmx and xms
Java: XMX and XMS - by roli agrawal - roli’s Substack
June 1, 2024 - The heap is where your Java objects live. Example: -Xmx1024m means the JVM can use up to 1024 megabytes (1 GB) of memory. ... This setting determines the initial amount of memory that the JVM allocates for the heap when it starts.
🌐
Squash
squash.io › how-to-use-java-option-xmx
How to Use the Xmx Option in Java - Squash Labs
November 3, 2023 - These options include Xms (initial heap size), Metaspace size (for managing class metadata), and more. Let's consider an example where we want to run a Java application called MyApp with a maximum heap size of 512 megabytes.
🌐
JavaMadeSoEasy
javamadesoeasy.com › 2016 › 10 › what-are-xms-and-xmx-jvm-parameters-in.html
JavaMadeSoEasy.com (JMSE): What are -Xms and -Xmx JVM parameters in java, And differences between them
So in this core java tutorial we learned what are -Xms and -Xmx JVM parameters in java, And differences between -Xms and -Xmx JVM parameters in java.
🌐
Javagyansite
javagyansite.com › 2023 › 08 › 06 › xms-and-xmx-parameters
Xms and Xmx Parameters in Java:Optimize Memory Allocation - Javagyansite
August 6, 2023 - If you set Xms to 256MB (-Xms256m), for example, the JVM will allocate 256 megabytes of memory as soon as the application starts. This can help to reduce the overhead of dynamic heap resizing during the initial execution phase.
🌐
Java2Blog
java2blog.com › home › core java › memory › what are xmx and xms parameters in java
What are Xmx and Xms parameters in java - Java2Blog
October 18, 2021 - -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. Let’s understand this with help of example.
🌐
CodeAhoy
codeahoy.com › 2019 › 09 › 02 › java-xmx-vs-xms
What are -Xms and -Xms parameters in Java/JVM (Updated up to Java 13) | CodeAhoy
September 2, 2019 - The Xmx parameter specifies the maximum memory an app can use, where as Xms specifies the minimum or the initial memory pool. If your application exceeds the maximum memory (allocated using the Xmx) and the garbage collector cannot free up memory, the JVM will crash with a OutOfMemoryError.
🌐
Eclipse Foundation
eclipse.dev › openj9 › docs › xms
-Xms / -Xmx -
The Oracle® HotSpot™ option -Xms sets the initial or the minimum Java™ heap size, and the -Xmx HotSpot option sets the maximum heap size.
🌐
Codemia
codemia.io › home › knowledge hub › what are the -xms and -xmx parameters when starting jvm?
What are the -Xms and -Xmx parameters when starting JVM? | Codemia
December 28, 2024 - System Resource Management: By ... memory Java applications use, you prevent them from negatively impacting the host operating system or other applications in terms of available memory. Stability and Predictability: Providing the JVM with adequate memory from the start can lead to more predictable application behavior under load, as the memory footprint grows and stabilizes earlier. Match -Xms and -Xmx: Setting -Xms ...
🌐
Baeldung
baeldung.com › home › java › jvm › guide to the most important jvm parameters
Guide to the Most Important JVM Parameters | Baeldung
January 8, 2024 - For example, if we want to assign minimum 2 GB and maximum 5 GB to JVM, we need to write: -Xms2G -Xmx5G · Starting with Java 8, the size of Metaspace isn’t defined. Once it reaches the global limit, JVM automatically increases it.