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
🌐
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.
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
Discussions

Increase heap size in Java - Stack Overflow
If I have 8G memory in my system ... to java heap size? 2017-01-18T15:27:32.8Z+00:00 ... @Reihan_amn Yes and no, if you exceed your memory it will go to paging, which is on the disk and incredibly slow. If you exceed the page files then you're in for a bad time. 2019-01-03T22:06:15.24Z+00:00 ... If this export cmd is used.... then will any java program by default be limited to 6Gb unless -Xm* values are specified at the java call? 2022-07-21T20:38:35.3... More on stackoverflow.com
🌐 stackoverflow.com
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
Java21 impressed memory usage!
Good reading for G1 changes in 18, 19, 20 and 21 https://tschatzl.github.io/2022/03/14/jdk18-g1-parallel-gc-changes.html https://tschatzl.github.io/2022/09/16/jdk19-g1-parallel-gc-changes.html https://tschatzl.github.io/2023/03/14/jdk20-g1-parallel-gc-changes.html https://tschatzl.github.io/2023/08/04/jdk21-g1-parallel-gc-changes.html More on reddit.com
🌐 r/java
21
214
September 11, 2024
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
🌐
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.
🌐
Azul
docs.azul.com › prime › Heap-Size
Recommended Heap Size | Azul Prime
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 ...
🌐
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.
🌐
Bell Software
bell-sw.com › blog › guide-to-jvm-memory-configuration-options
List of JVM memory configuration flags
March 14, 2024 - For instance, Alpaquita Linux has a base image size of 3.26 MB (musl) and 8.77 MB (glibc), perfect for Java microcontainers. Footprint (and startup) optimization is also possible by using Java with CRaC: give it a try!
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.
🌐
Reddit
reddit.com › r/java › java21 impressed memory usage!
r/java on Reddit: Java21 impressed memory usage!
September 11, 2024 -

Recently, our team updated our Spring Boot service to Java 21 for a project. Since we had already updated to Java 17 with Spring Boot 3.x version, the update to Java 21 was completed very easily, except for some issues with test cases.

However, a very significant change was observed in the memory usage of the service deployed on EKS. The heap memory usage decreased by nearly 50%, and native memory usage reduced by about 30%. We conservatively maintained the existing G1GC for garbage collection, yet the usage still decreased. After monitoring, we plan to halve the requested memory capacity within Docker.

Apart from this, CPU usage remained within the margin of error (we weren't using CPU close to the limit anyway). However, the minor GC count increased significantly.

We believe these effects are due to the preventive G1GC garbage collection patch introduced in Java 20.

We're curious if others have experienced similar changes when updating to Java 21 compared to previous versions.​​​​​​​​​​​​​​​​

🌐
Oracle
docs.oracle.com › en › java › javase › 21 › gctuning › ergonomics.html
HotSpot Virtual Machine Garbage Collection Tuning Guide
October 20, 2025 - The VM considers machines as server-class if the VM detects two or more processors and physical memory larger than or equal to 1792 MB. The Java HotSpot VM garbage collectors can be configured to preferentially meet one of two goals: maximum pause-time and application throughput.
🌐
IBM
ibm.com › docs › en › was-nd › 8.5.5
Modifying the JVM heap size - IBM Documentation
February 9, 2026 - The Java virtual machine (JVM) ... to modify the JVM heap size setting based on your environment configuration. The default value is 256 MB....
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › jvm-options-java-parameters-command-line-environment-variable-list-xms-xmx-memory
Critical Java JVM options and parameters
The following example sets the minimum heap size to 768 MB and the maximum to 2 GB. ... One of the benefits of Java is that the environment performs garbage collection for the developer, which makes applications more robust and less likely to ...
🌐
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.
🌐
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 › 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.
🌐
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 and Process Management, and click Process definition.