profiling - Java JAR memory usage VS class file memory usage -


i changed large java application delivered in jars instead of individual class files. have 405 jars hold 5000 class files. problem when run program(s) jars (classpath wildcard jars) java continually use more , more memory. have seen memory go > 2gb , seems java not doing stop-the-world garbage collections keep memory lower. if run exact same program against exploded jars (only class files), java's memory usage stays lower (< 256mb) , stays there. happening in oracle's java 8 on windows 7 (x64) , windows server (x64). why packaging application jars change memory profile? have run program long time jars memory maximum limited 128mb no problems don't have memory leak.

with jar files in classpath with jar files in classpath

with class files in classpath with class files in classpath

edit: accepted answer @k erlandsson because think best explanation , ugly quirk of java. every 1 (and @k erlandsson) help.

the first thing note how memory totally used on heap not interesting @ times, since of used memory can garbage , cleared next gc.

it how heap used live objects need concerned about. write in comment:

i don't know if matters, if use jvisualvm.exe force gc (mark sweep) heap memory usage drop clearing heap memory.

this matters. a lot. means when see higher heap usage when use jars, see more garbage, not more memory consumed live objects. garbage cleared when gc , well.

loading classes jar files consume more memory, temporarily, loading them class files. jar files need opened, seeked, , read from. requires more operations , more temporary data opening specific .class file , reading it.

since of heap usage cleared gc, additional memory consumption not need concerned about.

you write:

java continually use more , more memory. have seen memory go > 2gb , seems java not doing stop-the-world garbage collections keep memory lower.

this typical behavior. gc runs when jvm thinks necessary. jvm tune depending on memory behavior.

edit: see jconsole images see difference in committed heap memory (250 mb vs 680 mb). committed heap actual size of heap. vary (up set -xmx) depending on jvm thinks yield best performance application. however, increase, never decrease.

for jar case jvm has assigned bigger heap application. due more memory being required during initial class loading. jvm thought bigger heap faster.

when have bigger heap, more committed memory, there more memory use before running gc. why see difference in memory usage in 2 case.

bottom line: usage see garbage, not live objets, why not need concerned behavior unless have actual problem since memory reclaimed on next gc.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -