Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Problem in memory measurement of java program



Hi all,

I want to calculate the memory consumption in order to test the performance of my algorithm.
I am using jdk1.5.0_14 and trying to measure the memory of any array and Queue(provided by java API) using buit-in functions
"Runtime.getRuntime().totalMemory()and Runtime.getRuntime().freeMemory()." I am calculating the memory before defining an array and again calculate it after defining array and then calculate the difference of both to find the used memory.
But it is surprised that it shows me more as my expectation and even some time shows zero or same memory while I am creating multiple arrays.

Can anybody help me that how I can measure the exact memory consumed by all of objects in my algorithm?

Waiting for nice reply!!