java.lang.OutOfMemoryError: PermGen 空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3743992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.OutOfMemoryError: PermGen space
提问by Ganesamoorthy
I am getting following error frequently in eclipse IDE 3.2, how could I save the application from these OutOfMemory?
我在 Eclipse IDE 3.2 中经常出现以下错误,我如何从这些 OutOfMemory 中保存应用程序?
java.lang.OutOfMemoryError: PermGen space
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClassCond(Unknown Source)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1814)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
org.jboss.web.tomcat.service.WebAppClassLoader.findClass(WebAppClassLoader.java:75)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:111)
org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
com.mfic.util.HibernateUtil.<clinit>(HibernateUtil.java:16)
com.mfic.dao.BaseHome.getSession(BaseHome.java:16)
com.mfic.core.helper.UserManager.findByUserId(UserManager.java:248)
com.mfic.core.action.Login.authenticate(Login.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
回答by BalusC
Your project eats a lot of memory. Give Eclipse more memory to work with. Edit eclipse.ini
to modify or add the following lines below -vmargs
.
您的项目占用了大量内存。为 Eclipse 提供更多内存以供使用。编辑eclipse.ini
以修改或添加以下行-vmargs
。
-Xms256m -Xmx512m -XX:MaxPermSize=512m
Assuming you've at least 2GB of RAM.
假设您至少有 2GB 的 RAM。
See also:
也可以看看:
回答by Sam Day
This happens pretty frequently when running Tomcat inside Eclipse during debug sessions etc. From memory, it's an issue with the Sun JVM. Annnyway, there's an easy fix:
在调试会话等期间在 Eclipse 内运行 Tomcat 时,这种情况经常发生。从内存来看,这是 Sun JVM 的问题。Annnyway,有一个简单的解决方法:
Just add the following below your -vmargs in eclipse.ini (which is in the same directory as your eclipse binary):
只需在 eclipse.ini(与 eclipse 二进制文件位于同一目录中)中的 -vmargs 下方添加以下内容:
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled
This will enable a more aggressive garbage collection while running Eclipse, and is a more elegant solution than just throwing more RAM at Eclipse.
这将在运行 Eclipse 时启用更积极的垃圾收集,并且是一个比仅在 Eclipse 上投入更多 RAM 更优雅的解决方案。
Hope this helps!
希望这可以帮助!
回答by Pascal Thivent
Increase your MaxPermSize
in your eclipse.ini
. I suggest setting it to 128M or 256M if you're confortable with RAM
增加您MaxPermSize
的eclipse.ini
. 如果您对 RAM 感到满意,我建议将其设置为 128M 或 256M
-vmargs -XX:PermSize=64M -XX:MaxPermSize=128M
Also note that lots of people faced PermGen problems with Eclipse 3.2 as reported in Perm-Gen Errors Got You Down?. And since Eclipse 3.2 is more than 4 years old, I'd suggest upgrading to a more recent version (Eclipse 3.6 is the current version).
另请注意,许多人在 Eclipse 3.2 中遇到了 PermGen 问题,如Perm-Gen Errors Got You Down?. 由于 Eclipse 3.2 已有 4 年多的历史,我建议升级到更新的版本(Eclipse 3.6 是当前版本)。
References
参考
回答by Beel
The answers above probably solve it for you, but here are some interesting relevant links anyway:
上面的答案可能会为您解决,但这里有一些有趣的相关链接:
Here is an article with a lot of discussion and suggestions about this error: http://www.jroller.com/agileanswers/entry/preventing_java_s_java_lang
这里有一篇文章对这个错误有很多讨论和建议:http: //www.jroller.com/agileanswers/entry/preventing_java_s_java_lang
Discussion of an example of how a Permgen OOM error can occur: http://blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java
讨论 Permgen OOM 错误如何发生的示例:http: //blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java
Here is an actual solution, posted on StackOverflow recently. It is for Tomcat but may be useable in Eclipse: Dealing with "java.lang.OutOfMemoryError: PermGen space" error
这是一个实际的解决方案,最近发布在 StackOverflow 上。它适用于 Tomcat,但可能在 Eclipse 中可用: 处理“java.lang.OutOfMemoryError: PermGen space”错误
回答by Gangnus
If you are getting the questioned error in the secondary Eclipse Application, adding -XX:MaxPermSize=512m
in ini
won't help. You need to go into debug or run configuration->arguments
and add that piece in VM arguments.I also increased others memory limits so:
如果您收到在二级Eclipse的应用程序的质疑误差,增加-XX:MaxPermSize=512m
中ini
不会帮助。您需要进入debug or run configuration->arguments
并在 VM 参数中添加该部分。我还增加了其他内存限制,因此:
-Dosgi.requiredJavaVersion=1.5 -Xms120m -Xmx2048m -XX:MaxPermSize=1024m
It helped.
它有帮助。
Edit. After some experiments I've found, that Eclipse does take memory limits from the ini file. But... it does it only once, at the creation of a new workspace. Parameters from -vmarg in eclipse.ini create the default VM parameters line. So, if you are working on the existing workspace, change debug or run configuration. But change eclipse.ini, too, for better future.
编辑。经过一些实验,我发现 Eclipse 确实从 ini 文件中获取了内存限制。但是...它只执行一次,在创建新工作区时。来自 eclipse.ini 中 -vmarg 的参数创建默认的 VM 参数行。因此,如果您在现有工作区上工作,请更改调试或运行配置。但也要更改 eclipse.ini,以便更好的未来。
回答by Anand Kumar
And also after trying the above options, please check with updated JVM. I was using jdk1.6 and faced the same problem. When I changed the jvm in eclipse to JDK1.7, it is working fine.
并且在尝试上述选项后,请检查更新的 JVM。我正在使用 jdk1.6 并面临同样的问题。当我将 eclipse 中的 jvm 更改为 JDK1.7 时,它工作正常。
回答by Chand Priyankara
- Click on Server instance.
- Open Launch Configurations.
- Increase memory to JVM,in argument tab.
- 单击服务器实例。
- 打开启动配置。
- 在参数选项卡中增加 JVM 的内存。
-Xms64m -Xmx256m
-Xms64m -Xmx256m
See below images:
见下图:
回答by Ivo
Java applications are allowed to use only limited amount of memory. The exact amount of memory your particular application can use is specified during the application startup. To make things more complex, the Java memory is separated to different regions, one of which being called PermGen.
Java 应用程序只允许使用有限的内存量。您的特定应用程序可以使用的确切内存量是在应用程序启动期间指定的。为了让事情变得更复杂,Java 内存被分隔到不同的区域,其中之一称为 PermGen。
Size of all those regions is set during the JVM launch. If you do not explicitly set the sizes, platform-specific defaults will be used.
所有这些区域的大小都是在 JVM 启动期间设置的。如果您没有明确设置大小,将使用特定于平台的默认值。
So – the java.lang.OutOfMemoryError: PermGen space
message indicates that the Permanent Size area in memory is exhausted.
所以 – 该java.lang.OutOfMemoryError: PermGen space
消息表明内存中的永久大小区域已用完。
This specific area called PemGen is a dedicated region where Java classes are loaded and stored. This consists of the following:
这个称为 PemGen 的特定区域是加载和存储 Java 类的专用区域。这包括以下内容:
- Names of the classes
- Fields of the class
- Methods of a class with the bytecode of the methods
- Constant pool information
- Object arrays and type arrays associated with a class
- Just In Time compiler optimizations
- 班级名称
- 类的字段
- 带有方法字节码的类的方法
- 常量池信息
- 与类关联的对象数组和类型数组
- 及时编译器优化
That's pretty much it. Some more bits and pieces, but it does not impact the actual memory consumption by more than few percent. All these are allocated in the permanent generation and stay in the permanent generation.
差不多就是这样。更多的点点滴滴,但它不会影响实际内存消耗超过几个百分点。所有这些都在永久代中分配并留在永久代中。
As you can see, the permanent generation size requirements depend both upon the number of classes loaded as well as the size of such class declarations. So it is easy to see the main cause for such error: either too many classes or too big classes are being loaded to the permanent generation.
如您所见,永久代大小要求取决于加载的类的数量以及此类声明的大小。所以很容易看出导致这种错误的主要原因:太多类或太大类被加载到永久代。
Quick fix for symptoms is easy - if we have exhausted the PermGen area in the heap, we need to increase its size. This solution is indeed helpful if just have not given your JVM enough elbow room. So alter your application launch configuration and add (or increase if present) the following:
快速修复症状很容易——如果我们已经耗尽了堆中的 PermGen 区域,我们需要增加它的大小。如果只是没有给您的 JVM 足够的肘部空间,此解决方案确实很有帮助。因此,更改您的应用程序启动配置并添加(或增加如果存在)以下内容:
-XX:MaxPermSize=512m