1
votes

I was doing a quick experiment to see how my algorithm's memory performance looks like. The input is about 2 Mb and the algorithm takes about 1 second to run it. I ran this in a loop for 500 times to be able to look at the memory allocation.

This is how jConsole shows the memory usage:

enter image description here

As you can see heap memory usage increases (kinda exponentially) every two times before GC starts (even though the input is the same).

Does anybody know if this is expected and why it happens? Is it some optimization done by JVM?

Thanks!

1
it seems like your algorithm takes more time to run. Are you sure you are running the same number of iterates?JohnnyAW
@JigarJoshi if you look at the memory after a GC, you can see there isn't a memory leak (at least not a big one)Peter Lawrey
I agree -- not sign of a memory leak.Hot Licks
You cannot tell if that is expected without knowing the algorithm.Ale Sequeira

1 Answers

3
votes

Does anybody know if this is expected and why it happens? Is it some optimization done by JVM?

The JVM is trying to minimise the time spent GC-ing. If you use more memory, it doesn't have to GC as often.

a leak?

If you look at memory usage after a GC it is much the same so clearly it doesn't have a memory leak. Or at least not a big one.

You have to look at the memory used after Full GCs to confirm there is a memory leak and I assume these are minor collections.