简体   繁体   中英

Java high memory usage

I have a problem with a Java app. Yesterday, when i deployed it to have a test run, we noticed that our machine started swapping, even though this is not a real monster app, if you know what i mean. Anyway, i checked the results of top and saw that it eats around 100mb of memory (RES in top) I tried to profile memory and check if there is a memory leak, but i couldn't find one. There was an unclosed PreparedStatement, which i fixed, but it didn't mean much. I tried setting the min and max heap size (some said that min heap size is not required), and it didn't make any difference.

This is how i run it now:

#!/bin/sh

$JAVA_HOME/bin/java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9025 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -XX:MaxPermSize=40m -Xmx32M -cp ./jarName.jar uk.co.app.App app.properties

Here is the result of top :

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+ COMMAND                                                                                                                                                                          
16703 root      20   0  316m 109m 6048 S  0.0 20.8   0:14.80 java   

The thing i don't understand that i configure max PermSize and max Heap size, which add up to 72mb. Which is enough, the app runs well. Why is it eating 109mb of memory still and what is eating it up? It is a 37mb difference, which is quite high ratio. (34%). I don't think this is a memory leak, because max heap size is set and there is no out of memory error, or anything.

One intertesting thing may be that i made a heap dump with VisualVM and then checked it with EclipseMAT and it said that there is a possible leak in a classloader. This is what it says:

The classloader/component "sun.misc.Launcher$AppClassLoader @ 0x87efa40" occupies 9,807,664 (64.90%) bytes. The memory is accumulated in one instance of "short[][]" loaded by "".Keywords sun.misc.Launcher$AppClassLoader @ 0x87efa40

I cannot make much of this, but may be useful.

Thanks for your help in advance.

EDIT

I found this one, maybe there is nothing i can do... Tomcat memory consumption is more than heap + permgen space

Java's memory includes

  • the heap space.
  • the perm gen space
  • thread stack areas.
  • shared libraries, including that of the JVM (will be shared)
  • the direct memory size.
  • the memory mapped file size (will be shared)

There is likely to be others which are for internal use.

Given that 37 MB of PC memory is worth about 20 cents, I wouldn't worry about it too much. ;)

Did you try using JConsole to profile the application http://docs.oracle.com/javase/1.5.0/docs/guide/management/jconsole.html Otherwise you can also use JProfiler trial version to profile the application http://www.ej-technologies.com/products/jprofiler/overview.html?gclid=CKbk1p-Ym7ACFQ176wodgzy4YA

However first step to check high memory usage should be to check if you are using collection of objects in your application like array,map,set,list etc. If yes then check if they keep the references to objects (even though of not used) with them ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM