Is my Glassfish setup leaking memory?

2019-07-19 16:44发布

问题:

I've got a Glassfish v3 server running a few web applications (servlets, JSP, JDBC). I'd been noticing that if I let Glassfish run for a long time, it will consume all of the memory available (this is running on a server with 750 MB of memory).

I figured that there must be a memory leak, so I ran the server while monitoring it with JProfiler and noticed that when I get a peak in traffic, my memory usage shoots up (as expected), but then quickly drops back down.

I'm wondering if the issue is less of a memory leak, and more that Glassfish expands its heap size when the spikes occur (this does seem to be happening) but never decreases the heap size when the actual memory usage declines.

However, based on this graph, it does seem like the memory usage (blue) is trending upwards as the server runs longer.

My question is two-fold:

  1. Is there any way to have the heap size decreased when the actual memory usage drops after a spike?

  2. Is it probable that I do have a memory leak, or is this normal? What can I do to investigate this memory usage further?

回答1:

It does not look like a memory leak, as memory would keep on growing forever and it would really start blowing up with OOM errors, this is most likely the HotSpot compiler turning interpreted code into native code and this is surely going to claim memory and never give it back, as this memory goes to the eternal generation.

You should probably use a tool like JConsole or VisualVM to make sure that this is a leak and not something else.



回答2:

For 1. There is no way to do this.

For 2. you can use VisualVm to see where you are actually using memory.