This discussion is archived
0 Replies Latest reply: Sep 4, 2009 10:45 AM by 843829 RSS

Determining memory leak before OutOfMemoryException occurs

843829 Newbie
Currently Being Moderated
Summary:
Is there a way to determine if there is a memory leak (or other usage issue) in a JVM before an OutOfMemoryException occurs?

Details:
It would be nice to be able to notify someone if a service is about to have a memory-related issue before it occurs (since when it does occur, it probably renders the service inoperable).

My first approach was to calculate a percentage of memory used using Runtime methods (below) and based on that percentage notify on any percentage greater than a max amount.
+(totalMemory() - freeMemory()) / maxMemory()+
However, based on testing with the server hot spot Ive seen that this usage number can get pretty close to 100% before doing a full garbage collection which drops the usage down to below 40% (and continues to yo-yo like that over time). This pretty much renders this approach ineffective since it ends up notifying on normal operation.

I didnt see a VM option that may help and having trouble coming up with an alternative approach. Am I missing something in the VM options or is there another approach I havent thought of?
VM Options:
[http://www.j2ee.me/javase/technologies/hotspot/vmoptions.jsp]

Edited by: mbunks on Sep 4, 2009 10:44 AM