On Windows, you can use the following command to find out the defaults on the system where your applications runs.

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

I believe the resulting output is in bytes.

Answer from stones333 on Stack Overflow
Top answer
1 of 10
669

On Windows, you can use the following command to find out the defaults on the system where your applications runs.

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

I believe the resulting output is in bytes.

2 of 10
130

For Java SE 5: According to Garbage Collector Ergonomics [Oracle]:

initial heap size:

Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before J2SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. You can override this default using the -Xms command-line option.

maximum heap size:

Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.

UPDATE:

As pointed out by Tom Anderson in his comment, the above is for server-class machines. From Ergonomics in the 5.0 JavaTM Virtual Machine:

In the J2SE platform version 5.0 a class of machine referred to as a server-class machine has been defined as a machine with

  • 2 or more physical processors
  • 2 or more Gbytes of physical memory

with the exception of 32 bit platforms running a version of the Windows operating system. On all other platforms the default values are the same as the default values for version 1.4.2.

In the J2SE platform version 1.4.2 by default the following selections were made

  • initial heap size of 4 Mbyte
  • maximum heap size of 64 Mbyte
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-is-the-default-max-java-heap-size-determined
How is the default max Java Heap size determined? - GeeksforGeeks
July 23, 2025 - Server JVM heap configuration ergonomics are now the same as the Client, except that the default maximum heap size for 32-bit JVMs is 1 gigabyte, corresponding to a physical memory size of 4 gigabytes, and for 64-bit JVMs is 32 gigabytes, ...
Discussions

java - OpenJDK 17 heap memory issue - Stack Overflow
As it turns out, the JVM can avoid wasting memory by compressing the object pointers or oops, so we can have the best of both worlds: allowing more than 4 GB of heap space with 32-bit references in 64-bit machines! ... To enable oop compression, we can use the -XX:+UseCompressedOops tuning flag. The oop compression is the default behavior from Java 7 onwards whenever the maximum heap size ... More on stackoverflow.com
🌐 stackoverflow.com
Essential JVM Heap Settings: What Every Java Developer Should Know
An upcoming JEP intends to make heap sizing a thing of the past, first for ZGC, and later maybe for other collectors, too: Automatic Heap Sizing for ZGC . It didn't make JDK 25, but fingers crossed for JDK 26. More on reddit.com
🌐 r/java
22
133
August 4, 2025
Java memory usage in containers
You can set JVM initial and max ram percentages like so: -XX:InitialRAMPercentage=80 -XX:MaxRAMPercentage=80 Those flags cause the JVM to consume only that percentage of the pod memory, they were introduced in OpenJDK 10 [1]. This is better than setting Xmx within the docker container because it effectively lets you manage your JVM memory via the pod settings. Gives your k8s team control of actual memory usage. There were some issues with the implementation in JDK 11 which lead to OOMKilled errors (basically the flags were not respected, but that is resolved now). OOMKilled Details: https://factorhouse.io/blog/articles/corretto-memory-issues/ You still need pod level limits for those flags to take effect, but they're pretty useful. When you set your pod memory memory resources you should run with a guaranteed QoS [2] by setting both requested and limit to the same value. Guaranteed QoS means that the pod is least likely to be evicted [3]. resources: limits: memory: 8Gi requests: memory: 8Gi By the way 80% percentage is pretty high, probably safer in the general case to go with 70% cos the remaining memory will be required by the OS. Soure: I work at Factor House (and I wrote that blogpost about OOMKilled errors). We build dev tools for Apache Kafka and Apache Flink (written in Clojure, but runs on the JVM), we offer both an uberjar and a docker container that runs the uberjar as deployment methods, so we have a bit of experience tuning this stuff. [1] https://bugs.openjdk.org/browse/JDK-8146115 [2] https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/#create-a-pod-that-gets-assigned-a-qos-class-of-guaranteed [3] https://kubernetes.io/docs/concepts/workloads/pods/pod-qos/#guaranteed More on reddit.com
🌐 r/java
30
47
September 23, 2024
Why do Java containers need so much off-heap memory?
.5G os not required at all. The default is 64 MB for Off heap ( I believe you mean PermSize) for Server VMs. On newer JVMs, the MetaspaceSize ( PermSize is Metaspace) default is only 12 MB or as low as 20Mb, depending on the platform, though. Max Perm or max Metaspace sizes those are half of the physical memory but mostly never allocated. You can control this by - XX:PermSize=64M or -XX:MetaspaceSize=64M and limit -XX:MaxPermSize or -XX:MaxMetaspaceSize to let's say 128M or 256M etc. If you limit too much, the JVM won't start, though. More on reddit.com
🌐 r/java
31
14
February 22, 2023
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › gctuning › ergonomics.html
Ergonomics - Java
October 20, 2025 - The maximum pause-time goal is specified with the command-line option -XX:MaxGCPauseMillis=<nnn>. This is interpreted as a hint to the garbage collector that a pause-time of <nnn> milliseconds or fewer is desired. The garbage collector adjusts the Java heap size and other parameters related to garbage collection in an attempt to keep garbage collection pauses shorter than <nnn> milliseconds. The default for the maximum pause-time goal varies by collector.
🌐
IBM
ibm.com › docs › en › was-nd › 8.5.5
Modifying the JVM heap size - IBM Documentation
February 9, 2026 - Typically, the total value of all server instance JVM heap sizes on a specific node must be less than half of the total RAM of that computer. The default maximum heap size value is 256 MB.
🌐
W3Docs
w3docs.com › java
How is the default max Java heap size determined?
Here is the formula used by the JVM to calculate the default maximum heap size: For systems with less than 1 GB of physical memory, the default maximum heap size is set to 256 MB.
🌐
Baeldung
baeldung.com › home › spring › spring boot › what are the spring boot default memory settings?
What Are the Spring Boot Default Memory Settings? | Baeldung
January 8, 2024 - For example, we can allocate it to 512 kB: ... In this article, we have learned about the default values of various heap and stack memory configuration options available for Java applications.
🌐
IBM
ibm.com › docs › en › webmethods-integration › wm-universal-messaging › 11.1.0
Configuring the JVM Heap Size and Direct Memory - IBM Documentation
March 12, 2026 - wrapper.java.additional.17=-XX:MaxDirectMemorySize=512m ... The default value in the Server_Common.conf file is 1G (1 gigabyte). Restart the server for the changes to take effect.
Find elsewhere
🌐
Eclipse OpenJ9 Blog
blog.openj9.org › 2020 › 04 › 30 › default-java-maximum-heap-size-is-changed-for-java-8
Default Java Maximum Heap Size is changed for Java 8 – Eclipse OpenJ9 Blog
April 30, 2020 - The default values for Xmx is based on the physical memory of the machine. In current OpenJ9 release 0.19: For Java 11 and above The Xmx value is 25% of the available memory with a maximum of 25 GB.
🌐
Mike my bytes
mikemybytes.com › 2022 › 11 › 15 › what-happens-when-you-only-limit-the-maximum-heap-size
What happens when you only limit the maximum heap size? | Mike my bytes
November 15, 2022 - According to some tests I run with Docker, the default minimum heap size most likely is 8M, no matter how much memory is available. Yet, I can’t promise you it’s always like this.
🌐
Oracle
docs.oracle.com › cd › E92519_02 › pt856pbr3 › eng › pt › tsvt › task_WorkingWithJVMHeapSize-5f7fe4.html
Working With JVM Heap Size
Adjusting the JVM heap size settings can improve performance in some situations, however, the default settings are typically adequate for most situations. ... In the Administrative Console, select Servers, Server Types, WebSphere application servers, and click on your server in the resource list. Select the Configuration tab, and in the Server Infrastructure section expand Java ...
🌐
Medium
medium.com › @maheshwar.ramkrushna › understanding-heap-size-and-its-impact-on-java-application-performance-d4c312bbd13c
Understanding Heap Size and its Impact on Java Application Performance | by Ramkrushna Maheshwar | Medium
May 25, 2023 - The JVM heap is where objects created by a Java program are stored during runtime. By default, the initial heap size of a Java application is set to 1/64th of the computer’s physical memory or a reasonable minimum based on the platform, whichever value is larger.
🌐
Medium
medium.com › @marcoghisellini › spring-boot-default-memory-size-84b89ade7b10
Spring Boot — Default memory size | by Marco Ghisellini | Medium
April 18, 2025 - Jvm reserves half of physical memory for Max heap size and 1/64th of physically memory for Initial heap size. Unfortunately, this cannot be less than 8Mb, so, it sets this value as default.
🌐
Oracle
docs.oracle.com › cd › E74363_01 › ohi_vbp_-_installation_guide--20160224-094432-html-chunked › s66.html
2.7.2 JVM Options
Allocating too much memory can lead to lengthy garbage collection pauses and lengthy memory defragmentation (also known as compaction). That in turn may lead to system failures. Make sure that the maximum heap size does not exceed 8192 megabytes.
🌐
Baeldung
baeldung.com › home › java › jvm › jvm parameters initialrampercentage, minrampercentage, and maxrampercentage
JVM Parameters InitialRAMPercentage, MinRAMPercentage, and MaxRAMPercentage | Baeldung
June 5, 2024 - The MaxRAMPercentage parameter allows setting the maximum heap size for a JVM running with a large amount of memory (greater than 200 MB). First, let’s explore the default value of the MaxRAMPercentage: $ docker run openjdk:8 java ...
🌐
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 - (The -server flag increases the default size to 128M.) The maximum heap limit is about 2 GB (2048MB). When setting the Java heap size, you should specify your memory argument using one of the letters “m” or “M” for MB, or “g” or “G” for GB.
🌐
Highbyte
support.highbyte.com › kb › administration › infrastructure › adjust-default-jvm-heap-memory-size
Adjust Default JVM Heap Memory Size
August 7, 2025 - Learn how to optimize memory usage and improve performance for HighByte Intelligence Hub by adjusting the Java Virtual Machine (JVM) heap size. This guide explains default heap settings and how to configure them in the start-windows.bat file for Windows installations.
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › developer › java › containers › overview
Containerize your Java Applications - Java on Azure | Microsoft Learn
3 weeks ago - To set a minimum heap size, use -Xms for absolute amounts or -XX:InitialRAMPercentage for percentage amounts. ... Despite what the name suggests, the flag -XX:MinRAMPercentage sets the default maximum RAM percentage for systems with up to 256 MB of ...