memory - 电梯和码头的 PermGen 问题

标签 memory scala jvm lift permanent-generation

我正在标准 Lift 平台(maven 和 jetty)上进行开发。我反复(每两天一次)得到这个:

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

这是在我的开发环境中。这不是问题,因为我可以继续重新启动服务器。在部署中我没有这些问题,所以这不是一个真正的问题。我只是好奇。

我对 JVM 了解不多。我认为我认为永久代内存用于类和实习字符串之类的东西是正确的?我记得有点和.NET内存模型混淆了……

发生这种情况的任何原因?默认值是不是非常低?它是否与 Scala 必须为 Function 对象和类似的 FP 事物创建的所有辅助对象有关?每次我用新编写的代码(每隔几分钟)重新启动 Jetty 时,我想它会重新加载类等。但即便如此,它不可能有那么多可以吗?而且JVM不应该能够处理大量的类吗?

干杯

最佳答案

来自 this post :

This exception occurred for one simple reason :
the permgenspace is where class properties, such as methods, fields, annotations, and also static variables, etc. are stored in the Java VM, but this space has the particularity to not being cleaned by the garbage collector. So if your webapp uses or creates a lot of classes (I’m thinking dynamic generations of classes), chances are you met this problem. Here are some solutions that helped me get rid of this exception :

  • -XX:+CMSClassUnloadingEnabled : 此设置启用 permgenspace 中的垃圾回收
  • -XX:+CMSPermGenSweepingEnabled : 允许垃圾收集器从内存中删除偶数类
  • -XX:PermSize=64M -XX:MaxPermSize=128M :提高分配给 permgenspace 的内存量

这可能会有所帮助。

2012 年 7 月编辑(将近 3 年后):

Ondra Žižka评论(我已经更新了上面的答案):

JVM 1.6.0_27 says: Please use:

  • CMSClassUnloadingEnabled(使用CMS GC时是否开启类卸载)
  • 将来代替 CMSPermGenSweepingEnabled

查看完整的 Hotspot JVM Options - The complete reference为先生。

关于memory - 电梯和码头的 PermGen 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1451648/

相关文章:

c - 如何获得结构体中正确的偏移地址

c - 如何在 C 中编写线程安全、高效、无锁的内存分配器?

scala - Scala 2.9将添加哪些新功能?

java - 为基于云的构建和部署管理 paypal-api 凭据的好方法是什么?

garbage-collection - 由于 GC,Cassandra 修复失败

内存传输 Intel 组装 AT&T

C++ 三元运算符执行条件

java - JVM 页面错误应该为零,对吗?多高合适?

scala - 如何在 Scala 中定义包私有(private) *trait*?

Java ClassFile 附加字节?