Reputation: 10531
I am testing memory consumption of a block of code by using:
long totalMemory = Runtime.getRuntime().totalMemory();
long freeMemory = Runtime.getRuntime().freeMemory();
Used memory is the difference between totalMemory
and freeMemory
. I launched and run the same program three times with exactly same conditions. But the used memory amount differs a lot:
1120M
802M
312M
What might cause this? And should I take the average of the three as the memory usage of the code? First time doing this, and thanks for any insights on this.
Upvotes: 2
Views: 89
Reputation: 11
This is couse due to java java vitual machine (JVM). Java use three types of memmory structures.
So Garbage collector also run in JVM. That also effect to change memmory usage. You can reffer this link to more details.
http://www.yourkit.com/docs/kb/sizes.jsp
Upvotes: 1