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?
Asked
Active
Viewed 9,084 times
25

Simon Nickerson
- 42,159
- 20
- 102
- 127
2 Answers
38
You can use something like this:
Iterator<MemoryPoolMXBean> iter = ManagementFactory.getMemoryPoolMXBeans().iterator();
while (iter.hasNext())
{
MemoryPoolMXBean item = iter.next();
String name = item.getName();
MemoryType type = item.getType();
MemoryUsage usage = item.getUsage();
MemoryUsage peak = item.getPeakUsage();
MemoryUsage collections = item.getCollectionUsage();
}
This will give you all types of memory. You are interested in "Perm Gen" type.

jleft
- 3,457
- 1
- 23
- 35

kgiannakakis
- 103,016
- 27
- 158
- 194
-
2Thanks, this works. I am taking the MemoryPoolMXBean where name.equalsIgnoreCase("Perm Gen"). – Simon Nickerson Mar 30 '09 at 15:14
-
Needed info, Thank you kgiannakakis. – vissu Jul 12 '12 at 06:30