Hi
I have to calculate the memory consumed by my
Java program.
I have used following line in the program to calculate the memory
MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
MemoryUsage usage = mbean.getHeapMemoryUsage();
MemoryUsage nonHeapusage = mbean.getNonHeapMemoryUsage();
long total = (usage.getUsed()+nonHeapusage.getUsed())/1024;
That is displaying the memory consumed in KB.
But when I look at java.exe process in Task Manager on Windows machine, that was showing more memory consumed (approx 9MB more) than what is displayed by my calculation.
I have some questions on that:
1.Is the memory being consumed by some other mechanism other than heap and non heap?
2.Is there any other way to calculate the memory same as task manager?
3.What is this NonHeapMemoryUsage, is this same as stack?
4.The MemoryMXBean is returning the pool of memory by calling ManagementFactory.getMemoryPoolMXBeans(). What are those pools and whether they plays a role in memory consumption?
I have once added the memory usage by all the pools. That size is much bigger that Task Manager size. And is growing continuously.
Regards,
Amit Arora
SCJP,SCWCD