Ask a Question
Advertise on boostr.in
boostr.in questions - Question:Discrepancy between memory usage got through getMemoryMXBean() and jvisualvm?
When trying to monitor my own program's memory usage through the following code
public static String heapMemUsage()
¬†¬†¬†¬†long used = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
¬†¬†¬†¬†long max = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax();
¬†¬†¬†¬†return ""+used+" of "+max+" ("+ used/(double)max*100.0 + "%)";
I got a slightly different result than seen through jvisualvm (17 588 616 in my program vs 18 639 640 in jvisualvm). I know it's not that big of a deal, but it did get me thinking.
Is there any explanation for this fact?
I'd like to use the coded version if possible, but if its results are in some way skewed, being jvisualvm in some way more credible, I'll have to stick with jvisualvm instead.
Sep 13, 2013
Sep 12, 2013
to add a comment.
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please