Reputation: 4653
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:
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!
Upvotes: 1
Views: 2649
Reputation: 533530
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.
Upvotes: 3