IntelliJ IDE uses more memory than maximum heap size (Xmx)

Question

Why does the IDE consume more memory than specified in heap size defined as Xmx value in the .vmoptions file?

Answer

This is expected behaviour for any Java-based application. 

It is not possible to predict how much memory the IDE would realistically allocate with reasonable precision. It can be roughly calculated using this formula:

 

Xmx size + ReservedCodeCacheSize + Metaspace (dynamic) + 8 * 2 (Xss size (2M by default) * threads) + off-heap allocations via ByteBuffers + JNI code

 

Where

Metaspace is the runtime representation of Java classes within a JVM process - basically, any information the JVM needs to work with a Java class. 

ReservedCodeCacheSize is the amount of memory allocated for the JIT compiler code cache.

threads - 30, typically.

ByteBuffer allows allocating memory outside of the Java heap, which can reduce the load on the garbage collector. The IDE uses ByteBuffers as an intermediate cache when accessing its indices, among other things.

JNI is a Java Native Interface: code natively compiled for a specific architecture, shared libs within .so/.dll/.dylib files (depending on the operating system you’re running).



You can find more detailed information on the topic here:

https://plumbr.io/blog/memory-leaks/why-does-my-java-process-consume-more-memory-than-xmx

https://www.baeldung.com/jni

https://www.baeldung.com/java-permgen-metaspace

https://www.baeldung.com/native-memory-tracking-in-jvm

https://stuefe.de/posts/metaspace/what-is-metaspace/

6 out of 16 found this helpful
1 comment

After i change heap size to 8000 and click Save and Restart when i go to this menu again it shows current value: 1024 is 8000 not being applied?

0

Please sign in to leave a comment.

Have more questions?

Submit a request