Need clarification on memory usage of a jar

Viewed 90

I'm running a jar using this command. Note the memory parameters. (The jar size is 56MB)

java -jar -Xms64M -Xmx256M build/libs/account-1.0.0-SNAPSHOT.jar 

In my Ubuntu System Monitor, the jar memory usage is shown as below.

enter image description here

When I profile the jar using YourKit, it shows below, which doesn't add up to above memory usage.

enter image description here

What am I missing here?

1 Answers

The jar size is not related to the JVM memory usage at all.

A jar can hold classes, interfaces, but potentially also data that are not directly related to java like images, property files, text files, jsons and so on.

Also a jar holding only a single class cannot be compared with its memory usage. Infact the jar uses classes of the jre (String, ArrayList, ...) that are not present in the jar itself but are loaded in the memory.

What you can do examining the memory using a profiler is a check of the usage of the running application. Basically you can answers questions like:

  • Is the memory released when it is no more used?
  • Is there any sort of cache holding data and never releasing them?
  • Is there any object bigger then expected?
  • Can I decrease the quantity of memory for this application
  • How often is the garbage collector called?
  • Can I suggest to use a different kind of garbage collector?

In any case remember that the disk size of a jar is absolutely not related to the JVM memory usage

Related