We developed an highly CPU intensive Java server application that is having a serious memory leak (or so it seems). As time passes, the application seems to eat up increasingly more memory (as seen with Windows Task Manager) but if I analyse it a specialized Java profiler the memory seems to be staying the same. For example, in task manager I see the application taking over 8gb of memory and growing, but in the Java profiler I see that heap memory is at most 2gb. I tried all possible combinations of JAVA_OPTS (-Xmx, -Xms, all types of GC) and nothing worked, Is the Java process not releasing memory back to OS? Is there any way to force it to do so?
Asked
Active
Viewed 1,022 times
1
-
Maybe, leak is in JVM perm gen, which isn't counted as part of heap. What about perm gen size as reported by JVM? – Victor Sorokin Oct 08 '14 at 14:24
-
The perm gen size is constant at about 90mb, so I'm guessing this is not the problem :) – LucianRadu Oct 08 '14 at 14:31
-
You can force gc from command-line and see if it changes anything: http://stackoverflow.com/a/3524024/162634 Plus, what is JVM you use? Is it Oracle's? – Victor Sorokin Oct 08 '14 at 14:36
-
Yes, it's Oracle. Running a GC shows the heap memory dropping in the profiler but in Task Manager there's no change. – LucianRadu Oct 08 '14 at 14:59
-
Once JVM allocated some memory from OS, it **does not** free it so soon. JVM have a lot of optimisation rules that say: if I needed so much heap some time before it is possible I will need it in future. – przemek hertel Oct 08 '14 at 15:04
-
I tried evey optimisation I could think of, but nothing worked – LucianRadu Oct 08 '14 at 15:12
-
Don't use task manager its junk. – jgr208 Oct 08 '14 at 15:43
1 Answers
1
1)
I suggest you to set -Xmx2100m
and observe heap usage under load.
JVM may take as much OS memory as it decide to be performant, until it reaches Xmx limit. In modern JVMs default Xmx is calculated upon total memory available in OS, so it may be large value.
I think your app does not have memory leak, your JVM simply allocate a lot of memory, because it can.
Observe your JVM thru jvisualvm.
2)
Second suggestion - do you use any JNI code? Does your app call any native library (ie. dll under windows)?

przemek hertel
- 3,924
- 1
- 19
- 27
-
Yes, it does have a JNI call to some C++ functions. The C++ functions are memory leak free. – LucianRadu Oct 08 '14 at 15:03