最近,我在我的web应用程序中遇到了这个错误:
java.lang.OutOfMemoryError:永久生成空间
它是一个典型的Hibernate/JPA + IceFaces/JSF应用程序,运行在Tomcat 6和JDK 1.6上。 显然,这可能发生在重新部署应用程序几次之后。
是什么原因导致的,如何避免呢? 我该如何解决这个问题?
最近,我在我的web应用程序中遇到了这个错误:
java.lang.OutOfMemoryError:永久生成空间
它是一个典型的Hibernate/JPA + IceFaces/JSF应用程序,运行在Tomcat 6和JDK 1.6上。 显然,这可能发生在重新部署应用程序几次之后。
是什么原因导致的,如何避免呢? 我该如何解决这个问题?
当前回答
你最好尝试-XX:MaxPermSize=128M而不是-XX:MaxPermGen=128M。
我不能确切地说出这个内存池的使用情况,但它与装入JVM中的类的数量有关。(因此,为tomcat启用类卸载可以解决这个问题。)如果您的应用程序在运行时生成和编译类,则更可能需要比默认值更大的内存池。
其他回答
我也有类似的问题。 我的是基于JDK 7 + Maven 3.0.2 + Struts 2.0 +谷歌GUICE依赖注入的项目。
当我尝试运行mvn清洁包命令时,它显示以下错误和“BUILD FAILURE”发生
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException;java.lang.reflect.InvocationTargetException: null java.lang.reflect.InvocationTargetException 由:java.lang.OutOfMemoryError: PermGen space引起
我尝试了上面所有有用的技巧,但不幸的是,没有一个对我有效。 对我有效的方法如下:=>
转到pom.xml 搜索<artifactId>maven-surefire-plugin</artifactId> 添加一个新的<configuration>元素和<argLine>子元素,其中pass -Xmx512m -XX:MaxPermSize=256m,如下所示=>
< configuration > < argLine > -Xmx512m -XX: MaxPermSize = 256m < / argLine > < / configuration >
希望能有所帮助,编程愉快:)
解决方案是在启动Tomcat时将这些标志添加到JVM命令行:
-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
您可以通过关闭tomcat服务,然后进入tomcat /bin目录并运行tomcat6w.exe来做到这一点。在“Java”选项卡下,将参数添加到“Java选项”框。单击“确定”,然后重新启动服务。
如果你得到一个错误,指定的服务不存在作为一个安装的服务,你应该运行:
tomcat6w //ES//servicename
其中servicename是在services.msc
来源:orx对Eric敏捷回答的评论。
或者,你可以切换到JRockit,它处理permgen的方式不同于sun的jvm。它通常也有更好的性能。
http://www.oracle.com/technetwork/middleware/jrockit/overview/index.html
In case you are getting this in the eclipse IDE, even after setting the parameters --launcher.XXMaxPermSize, -XX:MaxPermSize, etc, still if you are getting the same error, it most likely is that the eclipse is using a buggy version of JRE which would have been installed by some third party applications and set to default. These buggy versions do not pick up the PermSize parameters and so no matter whatever you set, you still keep getting these memory errors. So, in your eclipse.ini add the following parameters:
-vm <path to the right JRE directory>/<name of javaw executable>
还要确保将eclipse中的首选项中的默认JRE设置为正确的java版本。
谁在IntelliJ中调试JBoss应用程序时遇到了同样的问题: 我刚刚在运行/调试配置的虚拟机选项中添加了-XX: MaxPermSize = 128m。你可以把它增加到256m,以确保它会工作。