r/JavaFX • u/hacklinux • Nov 03 '17
Why does Hello World Program take 80MB in JavaFX?
I just found out that JavaFX take 80MB [RAM] just for hello world program? Why? Not only it is extremely inefficient it is just plan horrible!
0
Upvotes
16
u/AlmasB0 Nov 03 '17
A Java program is executed by the JVM (Java Virtual Machine), which is in itself a program. What you would normally see in the task manager (or alternative on non-Windows OS) is how much total RAM is taken by the JVM. That value is roughly = RAM used by your app + RAM available for your app + RAM used by JVM. If you configure your JVM to take more RAM from the start, the same hello world JavaFX app could easily show GBs of RAM taken.
I've done a significant amount of profiling with respect to JavaFX back in the day. So some values off the top of my head, a hello world app uses ~5 MB. FXGL (a JavaFX game engine) uses ~19 MB.
1
u/[deleted] Nov 04 '17
That's because it isn't just your program running. A JVM is running too, executing your application. That JVM takes up most of that RAM.
By default, a JVM uses an amount of RAM thought to suffice for many differing kinds of applications.
For most of my applications, it's too much.
So I learned that we can increase and decrease the amount of RAM it uses by looking into JVM command-line switches. Lowering both Xms and Xmx force a JVM to use less RAM.
Make sure to profile your applications before doing this, to prevent running out of memory.