4

我需要帮助解决这个问题。我需要有人向我解释为什么会发生这种情况以及如何预防或避免它。

Exception in thread "Thread-747" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-748" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-759" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-760" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-764" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-765" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-766" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-767" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-773" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-774" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-780" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-781" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-788" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-789" java.lang.OutOfMemoryError: PermGen space
2011-06-20 14:42:10,668 [http-8080-6] ERROR [/CM].[grails]  - Servlet.service() for servlet grails threw exception
java.lang.OutOfMemoryError: PermGen space
2011-06-20 14:42:10,668 [http-8080-6] ERROR [/CM].[default]  - Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
: java.lang.OutOfMemoryError: PermGen space
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
        at _GrailsPackage_groovy$_run_closure8.doCall(_GrailsPackage_groovy:275)
        at _GrailsPackage_groovy$_run_closure8.call(_GrailsPackage_groovy)
        at _GrailsRun_groovy$_run_closure8.doCall(_GrailsRun_groovy:245)
        at RunApp$_run_closure1.doCall(RunApp.groovy:35)
        at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:427)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:415)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.executeTargets(Gant.groovy:590)
        at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: java.lang.OutOfMemoryError: PermGen space
--- Nested Exception ---
java.lang.OutOfMemoryError: PermGen space
Error automatically restarting container: java.lang.OutOfMemoryError: PermGen space
Error executing script RunApp: PermGen space
java.lang.OutOfMemoryError: PermGen space
Error executing script RunApp: PermGen space
Application context shutting down...
Application context shutdown.
4

4 回答 4

20

PermGen 是 JVM 内存的一个区域,用于加载类。

当你的应用程序执行时,它会使用越来越多的内存,尤其是在调试环境中,或者如果你大量使用闭包。

解决这个问题的方法是添加更多!

这是通过在启动应用程序时向 JVM 传递一个或两个参数来完成的。

参数是:

-XX:MaxPermSize=256m
-XX:PermSize=128m

(根据您的特定需求调整值)

PermSize 将是 PermGen 的初始大小,而 MaxPermSize 将是在抛出异常之前它将增加的最大大小,就像在您的帖子中一样。

默认情况下,它设置为64M,如果你有一个“真正的”应用程序,这并不多。

请注意:您的total memory usage遗嘱是:Heap size + Perm Size

于 2011-06-21T03:28:49.347 回答
1

如果您使用的是 Servlet 3.0 版,那么即使增加内存也无济于事,因为这是 groovy 编译器的问题。即将发布的新版本 1.8.2/1.9 (?) 将解决此问题。同时,您可以将 servlet 版本改回“2.5”(在 BuildConfig.groovy 中),这将解决此问题。

The drawback of changing the servlet version to 2.5 is that it cannot be deployed to Glassfish application server so the ugly workaround is change to 2.5 and use "run-app". When you want to deploy to glassfish change the servlet version to "3.0" in BuildConfig.groovy, run "war" and then deploy the war to Glassfish. Change it back to "2.5" to run on local dev machine again.

于 2011-09-06T01:43:41.617 回答
0

检查常见问题

问:天哪,我在开发模式下运行 Grails 时遇到 OutOfMemoryErrors 或 PermGen Space 错误。我该怎么办?

从 Grails 0.6 开始,Grails 使用预编译自动重新编译 Java 源代码和域类,然后重新启动服务器。如果服务器运行很长时间并且进行了许多更改,这可能会导致 permgen 空间耗尽。如果它对您不重要,您可以禁用此功能:

grails -Ddisable.auto.recompile=true 运行应用程序

Windows 上的 Grails 0.6 也存在一个问题,由于重新编译,您在开发模式下的活动期间会出现 OutOfMemoryErrors。这可以在 SVN 头中解决,但如果您看到这个问题,上述选项也可以提供帮助。

最简单的方法是在它发生时重新启动您的应用程序服务器。

于 2011-06-20T13:53:10.607 回答
0

In the STS IDE set as per following:

-XX:MaxPermSize=512m -XX:PermSize=128m

enter image description here

I hope it helps.

于 2015-09-03T18:44:45.257 回答