PermGen problems with the lift and berth

I am developing on the standard Lift platform (maven and pier). I repeatedly (every couple of days) receive the following:

Exception in thread "7048009@qtp-3179125-12" java.lang.OutOfMemoryError: PermGen space 2009-09-15 19:41:38.629::WARN: handle failed java.lang.OutOfMemoryError: PermGen space 

This is in my dev environment. This is not a problem because I can continue to restart the server. I have no such problems in the deployment, so this is not a real problem. I'm just curious.

I don't know too much about the JVM. I think I'm right in thinking that a constant generation memory is for things like classes and interned strings? What I remember is a bit mixed up with the .NET memory model ...

Any reason why this is happening? Are defaults just insanely low? Is this related to all the helper objects that Scala must create for Function objects and similar FP things? Every time I restart Jetty with a new code (every few minutes), I assume that it reloads the classes, etc. But even so, there can be so many? And shouldn't the JVM deal with a lot of classes?

Greetings

Joe

+41
scala memory jvm lift
Sep 20 '09 at 18:21
source share
5 answers

From this post :

This exception occurred for one simple reason:
permgenspace , where class properties such as methods, fields, annotations, as well as static variables, etc. stored in the Java virtual machine, but this space has the peculiarity not to be cleaned using a garbage cleaner. Therefore, if your webapp uses or creates many classes (Im thinking about dynamic generation of classes), most likely you are faced with this problem. Here are some solutions that helped me get rid of this exception:

  • -XX:+CMSClassUnloadingEnabled : this option allows garbage collection in permgenspace
  • -XX:+CMSPermGenSweepingEnabled : allows the garbage collector to remove even classes from memory
  • -XX:PermSize=64M -XX:MaxPermSize=128M : increases the amount of memory allocated for permgenspace

Perhaps this will help.

Edit July 2012 (almost 3 years later):

Comments by Ondra Žižka (and I updated the answer above):

JVM 1.6.0_27 says: Please use:

  • CMSClassUnloadingEnabled (Whether class unloading is allowed when using CMS GC)
  • instead of CMSPermGenSweepingEnabled in the future

See full JVM Parameters Hotspot - full link for mroe.

+44
Sep 20 '09 at 18:29
source share

If you see this when starting mvn jetty:run , set MAVEN_OPTS .

For Linux:

 export MAVEN_OPTS="-XX:+CMSClassUnloadingEnabled -XX:PermSize=256M -XX:MaxPermSize=512M" mvn jetty:run 

For Windows:

 set "MAVEN_OPTS=-XX:+CMSClassUnloadingEnabled -XX:PermSize=256M -XX:MaxPermSize=512M" mvn jetty:run 

It should be fine now. If not, increase -XX:MaxPermSize .

You can also put them in your environment.

+12
Jul 23 2018-12-12T00:
source share

This is due to class reloads as you suggested. If you use many libraries, etc., the sum of the classes will grow rapidly for each restart. Try to control an instance of your jetty with VisualVM to get an overview of memory consumption on reboot.

+3
Sep 22 '10 at 17:30
source share

The mailing list ( http://groups.google.com/group/liftweb/ ) is the official support forum for Lift, and where you can get the best answer. I don’t know the details of your dev installation (you don’t get into the details), but I assume that you are reloading your war in Jetty without restarting it. Lifting does not dynamically generate classes (as suggested by VonC above), but Scala compiles each closure as a separate class. If you add and remove closures to your code within a few days, it is possible that too many classes are loaded and never unloaded and do not take up permanent space. I suggest you turn on the JVM options mentioned above by VonC and see if they help.

+2
Sep 20 '09 at 19:06
source share

The permanent generation is where the JVM places stuff that probably won't (garbage) collected as custom class loaders.

Depending on what you are deploying, the perm gen setting may be low. Some combinations of applications and / or containers contain some memory leaks, so when the application becomes idle, sometimes some things, such as class loaders, are not collected, which causes Perm Space to fill up, creating your error.

Unfortunately, currently the best option in this case is to maximize the perm space with the following jvm flag (example for a size of 192 m):

 -XX:MaxPermSize=192M (or 256M) 

Another option is to make sure that the container or infrastructure is not a memory leak.

+1
Sep 20 '09 at 18:28
source share



All Articles