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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With