How can I prevent PermGen space errors in Netbeans?
Asked Answered
S

5

27

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?

Stacistacia answered 23/3, 2009 at 14:45 Comment(3)
see also #718050Larainelarboard
Why don't you upgrade to a more current version of NetBeans? 6.5 is really old.Brasher
@a_horse_with_no_name: As is this question. I asked it over three years ago.Stacistacia
F
33

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

Flesh answered 23/3, 2009 at 15:11 Comment(5)
OK, none of the answers really helped, but this one bought me the most time between restarts :)Stacistacia
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)Couteau
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.Foreman
one thing ; in netbeans there is different between run and deploy run worked for me like it make heap empty but deploy and deploy will not empty the heap properly i tested it 100% for my case and thanks to @Łukasz BownikMiniaturist
@Grundlefleck, #3718437Judaea
G
4

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

Galactopoietic answered 23/3, 2009 at 14:57 Comment(0)
M
3

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)

Magnetometer answered 6/12, 2011 at 10:27 Comment(0)
S
2

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"

Seton answered 23/3, 2009 at 14:54 Comment(0)
A
1

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.

Anaanabaena answered 23/3, 2009 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.