Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
325 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 etbeans.conf You should prefixe those options with -J and add them in netbeans_default_options (see comments in netbeans.conf for more informations).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...