How do I programmatically find out my PermGen space usage?
Asked Answered
A

2

25

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?

Afghani answered 30/3, 2009 at 14:0 Comment(0)
S
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.

Sanjiv answered 30/3, 2009 at 14:21 Comment(1)
Thanks, this works. I am taking the MemoryPoolMXBean where name.equalsIgnoreCase("Perm Gen").Afghani
A
3

Try ManagementFactory.getMemoryPoolMXBeans().

Aluminate answered 30/3, 2009 at 14:5 Comment(1)
Thank you for getting me started.Afghani

© 2022 - 2024 — McMap. All rights reserved.