Java - Odd memory consumption between x32 and x64

I was profiling the x64 version of my application because the memory usage was excessively high, it all seems to come from JavaFX MediaPlayer, I correctly release listeners and event handlers.

Here is a sharp contrast.

X32 version on startup

enter image description here

And now the x64 version on startup

enter image description here

The x32 version remains below 256 MB, while the x64 will shoot at a concert; this until both are left to play through their playlist.

All code is the same.

JDK: jdk1.8.0_20

JRE: jre1.8.0_20

VM arguments on both

-XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=70 -Xms3670k -Xmx256m -Dsun.java2d.noddraw=true -XX:+UseParallelGC 

The same problem occurs on another x64 Java application

enter image description here

Is this a mistake or am I missing something?

+7
java memory-leaks javafx
source share
2 answers

What you see is the memory usage of the entire JVM that starts your process. The -Xmx256m parameter limits the maximum heap space available for your application to allocate (and the JVM will ensure its execution). Outside the heap space, the JVM can use additional memory for many other purposes (I'm sure I will skip a few from the list below):

  • PermGen, which is now replaced by Metaspace. According to the documentation , there is no default restriction for this:

     -XX:MaxMetaspaceSize=size Sets the maximum amount of native memory that can be allocated for class metadata. By default, the size is not limited. The amount of metadata for an application depends on the application itself, other running applications, and the amount of memory available on the system. 
  • Stack space (memory used = (number of threads) * stack size. You can control this with the -Xss parameter

  • Empty space (either using ByteBuffers in your code, or using third-party pary libraries such as EHCache, which in turn use non-working memory)

  • JNI Code

  • GC (garbage collectors need their own memory, which again is not part of the heap and can vary greatly depending on the used collector and application memory usage)

In your case, you see an “almost doubling” of memory usage, plus probably a more relaxing distribution of metapass when moving from 32-bit to 64-bit JVM. Using -XX:MaxMetaspaceSize=128m is likely to reduce memory usage to 512 MB for a 64-bit JVM.

+3
source share

I do not know your application, respectively, how it is implemented.

One possible reason for such unexpected differences may be how much memory can be used before garbage collection. You might think that a machine with 64-bit words is allocated more memory, and then a machine with 32-bit words. The garbage collector may work less frequently, so there will be even more memory for garbage, even if it is really not needed or useful.

0
source share

All Articles