I have a java web application running on Sun Solaris 10 platform, the
java version is 1.5.0. Recently I found when I used TOP command to get
the memory used by my application it was over 1.5GB and kept
increasing. However when using the java.lang.Runtime.totalMemory() and
freeMemory() methods from my code the memory usage was way lower than
the size reported by TOP. From totalMemory() and freeMemory() method
calls I could see that there did not seem to have a memory leak in my
code and the GC was working properly however memory use reported by TOP
never decreased meaning that the GC never got kicked off???
Thanks,
Richard.
Ben_ - 17 Aug 2006 21:00 GMT
I don't know the internals of this particular implementation, but I know
that some JVM implementations never release the memory to the Operating
System, even when the heap was shrunk.
What you see with Runtime.totalMemory is the size of the heap. What you see
with top is the size of the process, for which the Java heap accounts for
most of the size, but not all (memory allocated by native code, etc).
Matthias Ernst - 19 Aug 2006 11:50 GMT
Hi GNS,
> I have a java web application running on Sun Solaris 10 platform, the
> java version is 1.5.0. Recently I found when I used TOP command to get
> the memory used by my application it was over 1.5GB and kept
> increasing. However when using the java.lang.Runtime.totalMemory() and
> freeMemory() methods from my code the memory usage was way lower than
> the size reported by TOP.
By any chance, are you using File.deleteOnExit()? The method "leaks" memory
in native space outside the java heap - deleting such a file yourself does
not free that registration. Very hard to diagnose.
See
http://www.bobcongdon.net/blog/2005/07/filedeleteonexit-is-evil.html or http://blogs.sun.com/roller/page/chegar?entry=diagnosing_deleteonexit_issues
Matthias