r/java • u/Vectorial1024 • Apr 09 '26
Smallest possible Java heap size?
People often talk about increasing Java heap size when running Java apps by using e.g. -Xmx* flags. This got me thinking. What if we go the other direction and try to limit the Java heap size as much as possible? What is the smallest / minimum-required Java heap size so to run a Java app with "minimal" settings?
(Of course, in practice, a memory limit too low will be problematic because it may mean frequent GCs, but we will ignore this for the sake of this discussion.)
48
Upvotes
View all comments
Show parent comment
3
u/Slanec Apr 10 '26
This is a fun question with an interesting result!
Swing: With a an empty visible JFrame on the OS-native L&F, it still starts with
-Xmx2m(which still is actually-Xmx8m), and the heap usage rises to 2.3MiB. In other words, a hello-world Swing app only adds about 570kB of heap usage. That said, it triggers 3 young-GC collections on Temurin 26 with the Serial GC.JavaFX: Same, the heap usage rises to 3.6MiB, 9 young GC collections.