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 - The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one-fourth of the physical memory up to a physical memory size of 1 gigabyte.
Discussions

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 21 occupying more memory in ram than the heap size
The JVM often doesn't want to give back memory it requests to the OS. It's a lot slower to ask more memory from the OS than to reuse memory you already have. In some configurations the JVM is even unable to give back memory due to design limitations. It's very possible that the JVM requested all the heap memory it was allowed early on and keeps hanging on to it even if unused, especially as the limit is quite low. More on reddit.com
🌐 r/javahelp
19
5
March 7, 2025
Java sets max heap size at 25% of instance memory instead of allocated resource memory
Nomad version 1.4.3 Operating system and Environment details Amazon Linux 2, OpenJDK 11.0.21 Issue By default, Java sets max heap size at 25% available memory and recognizes limits set on container... More on github.com
🌐 github.com
2
October 30, 2023
java - Set default heap size in Windows - Stack Overflow
I want to set Java heap size permanently and don't want to run every jar file with options. I use Windows and Java 1.7. More on stackoverflow.com
🌐 stackoverflow.com
People also ask

How do I check Java default heap size settings on Linux
ANS: Execute the command: java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'
🌐
sqlpey.com
sqlpey.com › java › java-default-heap-size-calculation-and-configuration-methods
Java Default Heap Size Calculation and Configuration Methods …
What is the default MaxRAMPercentage value in recent Java versions
ANS: The default value for -XX:MaxRAMPercentage is 25.0% of usable physical RAM.
🌐
sqlpey.com
sqlpey.com › java › java-default-heap-size-calculation-and-configuration-methods
Java Default Heap Size Calculation and Configuration Methods …
Should -Xms and -Xmx always be set to the same value
ANS: Setting -Xms and -Xmx identically enhances predictability by removing dynamic resizing decisions from the JVM, though the JVM cannot then shrink the heap if resources are low elsewhere.
🌐
sqlpey.com
sqlpey.com › java › java-default-heap-size-calculation-and-configuration-methods
Java Default Heap Size Calculation and Configuration Methods …
🌐
Oracle
docs.oracle.com › en › graalvm › jdk › 21 › docs › reference-manual › native-image › optimizations-and-performance › MemoryManagement
Memory Management
April 21, 2026 - Note that GraalVM releases up to (and including) 21.3 use a different default configuration for the Serial GC with no survivor regions, a young generation that is limited to 256 MB, and a default collection policy that balances the time that is spent in young collections and old collections.
🌐
Azul
docs.azul.com › prime › Heap-Size
Recommended Heap Size
Intel Ice Lake and newer x86 processors, when 5-level paging (LA57) is enabled at the OS level, can have a maximum heap size of 14000 GB (14 TB). + When ZST is installed, the default value is 1GB and the maximum is 20000GB (20TB). -Xms<size>[m|M|g|G] Starting with 21.07.0.0, this flag specifies ...
🌐
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.
🌐
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.
🌐
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.
Find elsewhere
🌐
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 - We recommend increasing the maximum heap allocation to 512 MB or 1024 MB when dealing with discovery ranges equivalent to a class B subnet, or in excess of 30,000 addressable devices. This is because the default maximum Java heap size is 256 MB, ...
🌐
W3Docs
w3docs.com › java
How is the default max Java heap size determined?
For systems with 1 GB or more of physical memory, the default maximum heap size is set to 1/4 of the physical memory up to a maximum of 1 GB. For example, on a system with 4 GB of physical memory, the default maximum heap size would be calculated ...
🌐
sqlpey
sqlpey.com › java › java-default-heap-size-calculation-and-configuration-methods
Java Default Heap Size Calculation and Configuration Methods …
July 29, 2025 - Maximum Heap Size (-Xmx): Typically defaulted to 64MB. Initial Heap Size (-Xms): Varied by platform, based on a “reasonable minimum.” · Java 5.0 introduced the concept of a server-class machine, defined as having 2 or more physical processors AND 2 or more GBytes of physical memory (excluding ...
🌐
Baeldung
baeldung.com › home › java › jvm › jvm parameters initialrampercentage, minrampercentage, and maxrampercentage
JVM Parameters InitialRAMPercentage, MinRAMPercentage, and MaxRAMPercentage | Baeldung
June 5, 2024 - The MinRAMPercentage parameter, unlike its name, allows setting the maximum heap size for a JVM running with a small amount of memory (less than 200MB). First, we’ll explore the default value of the MinRAMPercentage: $ docker run openjdk:8 ...
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › gctuning › ergonomics.html
Ergonomics - Java
October 20, 2025 - Ergonomics is the process by which the Java Virtual Machine (JVM) and garbage collection heuristics, such as behavior-based heuristics, improve application performance. The JVM provides platform-dependent default selections for the garbage collector, heap size, and runtime compiler.
🌐
Reddit
reddit.com › r/javahelp › java 21 occupying more memory in ram than the heap size
r/javahelp on Reddit: Java 21 occupying more memory in ram than the heap size
March 7, 2025 -

Hi all... I have created a service in Java 21 using the latest springboot version 3.x.x series. When I deploy the service in live. I had allocated 2gb Ram and 1 Core Cpu for the pod. I was using internal cache that is EHCache, this tells why I have used 2gb Ram. After serving the requests for some time, the memory percentage of the pod had reached 95%, this was not expected as it was serving low numberiof requests. So I took a heap and analysed it. Below are the observations.

  • Used heap size is 113mb

  • Large memory object is EHCache 60mb (expected)

  • Unreferenced objects 400mb

  • GC algorithm used ( SerialGC) By taking heap dump I could not find much information. But what I observed is much memory objects were unreferenced objects. But GC should have cleared these. I saw online insstackoverflow, articles were telling most of them had faced same problem but did not post solutions to it. Many suggested to use different GC algorithm, so I ran the pod with G1GC algorithm. There was no significant observation seen. I am out of options now. Can somebody help me if they faced same issue and kindly post your solution. Thanks in Advance

Top answer
1 of 4
5
The JVM often doesn't want to give back memory it requests to the OS. It's a lot slower to ask more memory from the OS than to reuse memory you already have. In some configurations the JVM is even unable to give back memory due to design limitations. It's very possible that the JVM requested all the heap memory it was allowed early on and keeps hanging on to it even if unused, especially as the limit is quite low.
2 of 4
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Blogger
javarevisited.blogspot.com › 2011 › 05 › java-heap-space-memory-size-jvm.html
10 points about Java Heap Space or Java Heap Memory
Heap in Java is generally located ... garbage collection works in Java. The default size of Heap space in Java is 128MB on most of 32 bit Sun's JVM but its highly varies from JVM to JVM e.g....
🌐
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 - From OpenJ9 release 0.20, The default Java Maximum Heap Size (Xmx) is changed to be consistent with Java 11, so by default in Java 8, 25% physical memory up to 25GB for the Xmx will be expected.
🌐
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 ...
🌐
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.
🌐
GitHub
github.com › hashicorp › nomad › issues › 18920
Java sets max heap size at 25% of instance memory instead of allocated resource memory · Issue #18920 · hashicorp/nomad
October 30, 2023 - Nomad version 1.4.3 Operating system and Environment details Amazon Linux 2, OpenJDK 11.0.21 Issue By default, Java sets max heap size at 25% available memory and recognizes limits set on container...
Author   hashicorp