Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent PermGen space errors in Netbeans?

Every 15-30 minutes Netbeans shows a "java.lang.OutOfMemoryError: PermGen space". From what I learned from Google this seems to be related to classloader leaks or memory leaks in general.

Unfortunately all suggestions I found were related to application servers and I have no idea to adapted them to Netbeans. (I'm not even sure it's the same problem)

Is it a problem in my application? How can I find the source?

like image 784
Daniel Rikowski Avatar asked Mar 23 '09 14:03

Daniel Rikowski


People also ask

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.

What causes PermGen space error?

lang. OutOfMemoryError: PermGen Space is a runtime error in Java which occurs when the permanent generation (PermGen) area in memory is exhausted. The PermGen area of the Java heap is used to store metadata such as class declarations, methods and object arrays.

How do I fix Java Lang OutOfMemoryError PermGen space?

OutOfMemoryError: PermGen space. As explained in the above paragraph this OutOfMemory error in java comes when the Permanent generation of heap is filled up. To fix this OutOfMemoryError in Java, you need to increase the heap size of the Perm space by using the JVM option "-XX: MaxPermSize".

What is the replacement for PermGen space in Java 8?

In JDK 8.0 the Permanent Generation (PermGen) space has completely been removed and is kind of replaced by a new space called Metaspace.


1 Answers

It is because of constant class loading.

Java stores class byte code and all the constants (e.g. string constants) in permanent heap that is not garbage collected by default (which make sense in majority of situations because classes are loaded only once during the lifetime of an application).

In applications that often load classes during an entire lifetime that are:

  • web and application servers during hot redeployment;
  • IDE's when running developed applications (every time you hit Run button in Netbeans or eclipse it loads your application's classes a new);
  • etc this behavior is improper because a heap fills full eventually.

You need to turn on permanent heap garbage collection to prevent this error.

I use options

-XX:MaxPermSize=256M -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled 

(stopped my eclipse 3.4 from throwing "java.lang.OutOfMemoryError: PermGen space" so it should also work with netbeans).

Edit: Just note that for Netbeans you set those options in: [Netbeans installation]\etc\netbeans.conf You should prefixe those options with -J and add them in netbeans_default_options (see comments in netbeans.conf for more informations).

like image 58
Łukasz Bownik Avatar answered Oct 14 '22 07:10

Łukasz Bownik