views:

2945

answers:

4

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.

Unfortunatly 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?

+1  A: 

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"

kgiannakakis
+1  A: 

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.

Maurice Perry
+2  A: 

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

jassuncao
+3  A: 

It is because of constant class loading.

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

In applications chat often load classes during an entire liftime that are: - web and application servers during hot redeployment; -IDE's when runing developped applications (every time U hit Run button in Netbeans or eclipse it loads your application's classes a new); - etc this behavior is imporpoer because a heap fills full eventually.

U need to turn on permament 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).

lbownik
OK, none of the answers really helped, but this one bought me the most time between restarts :)
DR
try to icrease MaxPermSize to 512M or more beacuse garbage collecting permament hep will still not help if an application ties to store there more than it can contain (the amount of alive permamanet objects exceedes permament heap capacity)
lbownik
The arguments seemed to work for me (byte code analysis of rt.jar in my case), however, I did get the warning `Please use CMSClassUnloadingEnabled in place of CMSPermGenSweepingEnabled in the future`. Still worked though.
Grundlefleck