Hello,

Through developing JavaFX apps on Linux (X11, KDE) I always see the pattern when process (native?) memory doesn't get released back to the OS.

1. when app starts, the Java process consumes a relatively small amount of RAM (I track this via top or DE system monitor), usually around 120Mb. 2. if you do any manipulation with Stage (like resize it several times, or open the context menu several times) the memory process usage goes up to 130Mb. 3. then comes GC, which collects some _heap_ memory and returns it back to the OS depending on JVM settings, let say -5Mb
4. I repeat step 2, and JVM process process usage goes up again, +10Mb
5. again GC collects some _heap_ memory and uncommits it back to OS, -5Mb

I have profiled the application with JDK 21 / JavaFX 21 and the following settings:
-Xms32m
-Xmx64m
-XX:+UseZGC
-XX:+ZUncommit
-XX:ZUncommitDelay=30

Heap is not a problem, it's always ~20-30MB.
Metaspace is not a problem either, it's always around 2-4MB.

It looks like native (stack, thread?) memory leaks, so never returned to the OS. I've never seen JavaFX app process memory usage return (not even close) to the same value it started with. RAM usage increases gradually and can be 1.5, 2, 3 times the initial value. Yet the heap usage never rises above the -Xms value.

I run the same application (it's basically an empty stage) on Windows and see no such behavior. Process memory usage returns back to initial value almost immediately. Also, on Windows the JVM is freeing memory even without using ZGC.

How should I profile this? Any hints?

Reply via email to