Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically find out my PermGen space usage?

Tags:

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?

like image 383
Simon Nickerson Avatar asked Mar 30 '09 14:03

Simon Nickerson


People also ask

What is PermGen memory space?

PermGen (Permanent Generation) is a special heap space separated from the main memory heap. The JVM keeps track of loaded class metadata in the PermGen. Additionally, the JVM stores all the static content in this memory section.

How can you control size of PermGen space?

To fix it, increase the PermGen memory settings by using the following Java VM options. -XX:PermSize<size> - Set initial PermGen Size. -XX:MaxPermSize<size> - Set the maximum PermGen Size. In the next step, we will show you how to set the VM options in Tomcat, under Windows and Linux environment.

Why does Java 8 remove PermGen space?

The main reason for removing PermGen in Java 8 is: It is very hard to predict the required size of PermGen. It is fixed size at startup, so difficult to tune. Future improvements were limited by PermGen space.

Is method area and PermGen same?

Method Area is a part of space in the PermGen and it is used to store the class structure and the code for methods and constructors. The biggest disadvantage of PermGen is that it contains a limited size which leads to an OutOfMemoryError.


1 Answers

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.

like image 52
kgiannakakis Avatar answered Oct 12 '22 10:10

kgiannakakis