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?

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).


Try to add the following argument to netbeans netconf: -J-XX:MaxPermSize=256m


See this link on how to set the size of PermSize. Most probably this isn't a problem of your code, so the only solution would be to increase the the PermSize. I have found that this is quite often, when you work with JAXB. In general, if you use many libraries that themselves also depend on many other jar files, the default size of the PermGen space may not be big enough.

See these blog posts for more details: Classloader leaks and How to fix the dreaded "java.lang.OutOfMemoryError: PermGen space"


If you are developing a web application, try to put on server vm option

-Xmx512m -Xms512m -XX:MaxPermSize=512m

Go to Tools/Servers//Platform/VM Options (Netbeans 7.4)


You can change the startup options of netbeans JVM by editing the file /etc/netbeans.conf. I often have this kind of errors when I develop a Webapp and I deploy it often. In that case, I restart tomcat from time to time.


Need Your Help

How many characters in varchar(max)

sql-server-2008 size varchar

How many characters can a SQL Server 2008 database field contain when the data type is VARCHAR(MAX)?