user2524670
user2524670

Reputation: 277

Memory leak in Java application

I have an application, that among other things uses SSL. The point of the application is that it will run infinitely. The problem now is, it seems, that over time i get the following image:

Leaking

Now in the beginning, I take a look at the heap dump (with Memory Analyzer Tool from eclipse) at 2 points: 1 when my app reaches the highest point of memory usage and at the lowest (where, i presume a garbage collection occured.) In the beginning everything is fine, my app has a couple of objects in the finalizer queue and these dissapear. But half hour later, for no apparent reason, while the garbage collection occurs, the references to the finalizer class do not dissapear. These keep increasing in size, and there are 10 references, which point to an object and to the next finalizer in queue, that keep reoccuring. So its actually a repeating chain, of references to the same things, that never gets collected. While this did get collected in the beginning.

So my question is actually 2 fold: first question: What could be the cause of this to suddenly not get collected? (Because I've looked in my code pretty carefully, I'm fairly certain I do close the things that are being referenced by the finalizer class (inputstreams and outputstreams, apparently. Also some abstract stuff from the SSL library i'm using, but fairly certain there is nothing to close there. I'm using a general Client.getConnectionManager().shutdown() which I suppose should clear that up, which it does in the beginning). Could it be, that while the app repeats itself over and over, that for some reason the reference queue got too big and the collector just can't handle it?

Second question is: how might I go about to solving this issue? The image you are seeing is btw from the Jconsole, and when i perform the manual GC, these do all dissapear, and start over.

Any help or nudge in the right direction is much appreciated.

Upvotes: 0

Views: 393

Answers (3)

npe
npe

Reputation: 15699

If full GC clears the situation and moves the bottom memory usage back to the initial 10MB, this means that the Eden space / Survivor space is to small and/or objects are too early being promoted to Old generation (which means they will only be collected when Full GC occures).

I'd suggest starting with the resize of the Eden space and Survivor space.

Check out Tuning Garbage Collector documentation and Java VM Options for flags like XX:NewRatio, XX:SurvivorRatio and others that tune up Garbage Collection.

Also read about XX:InitialTenuringThreshold and XX:MaxTenuringThreshold - those two define thresholds for putting objects into Old generation. When used wisely, those two can make your objects stay in Survivor space longer, and get collected without Full GC.

Upvotes: 1

hanish.kh
hanish.kh

Reputation: 517

Its not necessarily be memory leak. I do find this fluctuations in the program that runs continuously for months. Once garbage collection occurs, it goes back to normal stage. I'm not sure, but sometimes I have seen that using a profiler makes the fluctuation drastic.

Upvotes: 0

rolfl
rolfl

Reputation: 17707

I doubt you have a memory leak at all. What you have is a garbage collector that has not needed to do a full collection. Not to diminish the nature of your program, but it is really quite small, and you have not run it for very long. Certainly not enough to confirm whether there are leaks.

The memory changes you have seen so far are just 'scavenges', and there have not yet been any serious collections yet. Give the GC a chance to do it's job.

Typically the only time any serious collection happens is when there is memory pressure, so expect the more aggressive collections to happen when your various secitons of the heap get full. Right now you are not even close.

Specifically, you have told java it can use about 90MB of memory, and you are currently only using 25MB.... what's the problem?

Upvotes: 2

Related Questions