I'm trying to diagnose a java.lang.OutOfMemoryError: PermGen Space
error when running on Sun's Hotspot JVM, and would like to know how much PermGen space my program is using at various points. Is there a way of finding out this information programmatically?
views:
647answers:
2Thank you for getting me started.
Simon Nickerson
2009-03-30 15:14:48
+9
A:
You can use something like this:
iter = ManagementFactory.getMemoryPoolMXBeans().iterator();
while (iter.hasNext())
{
MemoryPoolMXBean item = (MemoryPoolMXBean) iter.next();
name = item.getName();
type = item.getType();
usage = item.getUsage();
peak = item.getPeakUsage();
collections = item.getCollectionUsage();
}
This will give you all types of memory. You are interested in "Perm Gen" type.
kgiannakakis
2009-03-30 14:21:32
Thanks, this works. I am taking the MemoryPoolMXBean where name.equalsIgnoreCase("Perm Gen").
Simon Nickerson
2009-03-30 15:14:12