错误 java.lang.OutOfMemoryError: PermGen space
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23488101/
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
Error java.lang.OutOfMemoryError: PermGen space
提问by user3588852
In my project i get error like below :
在我的项目中,我收到如下错误:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/ExamSy stem] threw exception [javax.servlet.ServletException: java.lang.OutOfMemoryErro r: PermGen space] with root cause
java.lang.OutOfMemoryError: PermGen space
May 06, 2014 2:44:18 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /home/anything/public_html/ExamSystemold .war
May 06, 2014 2:47:08 AM org.apache.tomcat.util.digester.Digester startElement
SEVERE: Begin event threw error
java.lang.OutOfMemoryError: PermGen spaceException in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" jav a.lang.OutOfMemoryError: PermGen space
Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" jav a.lang.OutOfMemoryError: PermGen space
回答by gyanu
When you have PermGen space OutOfMemoryError you have to check the value XX:MaxPermSize=XXXM.
当您有 PermGen 空间 OutOfMemoryError 时,您必须检查值 XX:MaxPermSize=XXXM。
The permanent space is where the classes, methods, internalized strings, and similar objects used by the VM are stored and never deallocated.
永久空间是存储 VM 使用的类、方法、内部化字符串和类似对象的地方,永远不会被释放。
- Generally for web applications due to jsp dynamic class generations and hot redeployment, memory uses is going to increase with multiple copies of same class.
- Max Heap Size (-Xmx) and MaxPermSize should be set considering how much memory is required for application classes and instances, total memory of server or machine and memory required for application. There should be safe space between Max Heap Size (-Xmx) and MaxPermSize for application execution.
Check memory leaks
Starting with Java 8, both the permgen space and this setting are gone. User won't have this error.
- 通常对于 web 应用程序,由于 jsp 动态类生成和热重新部署,内存使用会随着同一类的多个副本而增加。
- Max Heap Size (-Xmx) 和 MaxPermSize 应该根据应用程序类和实例需要多少内存、服务器或机器的总内存以及应用程序所需的内存来设置。Max Heap Size (-Xmx) 和 MaxPermSize 之间应该有安全空间用于应用程序执行。
检查内存泄漏
从 Java 8 开始,永久生成空间和此设置都消失了。用户不会有这个错误。
References:
参考:
回答by Sanjaya Pandey
Once you come across the PermGen Space issue, you will need to find out if the issue is due to large number of classes your application is loading or due to memory leak. If it is due to large number of classes, you can fine tune to increase the PermGen Space allocated and that will resolve the issue.
一旦您遇到 PermGen Space 问题,您将需要找出问题是由于您的应用程序正在加载大量类还是由于内存泄漏。如果是由于大量类,您可以微调以增加分配的永久代空间,这将解决问题。
The 1st reason could be your application or your server has too many classes and the existing PermGen Space is not able to accommodate all the classes. **-XX:MaxPermSize=XXXM**
第一个原因可能是您的应用程序或您的服务器有太多的类,而现有的永久代空间无法容纳所有的类。**-XX:MaxPermSize=XXXM**
If the issue is due to insufficient PermGen Space due to large number of classes, then you can increase the PermGen space by adding the –XX:MaxPermSize=XXm parameter. This will increase the space available for storing the classes and should -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled
如果问题是由于大量类导致 PermGen 空间不足,那么您可以通过添加 –XX:MaxPermSize=XXm 参数来增加 PermGen 空间。这将增加可用于存储类的空间,并且应该 -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled
This parameter indicates whether class unloading enabled when using CMS GC. By default this is set to false and so to enable this you need explicitly set the following option in java options.
此参数指示使用 CMS GC 时是否启用类卸载。默认情况下,它设置为 false,因此要启用它,您需要在 java 选项中明确设置以下选项。
-XX:+CMSClassUnloadingEnabled
-XX:+CMSClassUnloadingEnabled
If you enable CMSClassUnloadingEnabled the GC will sweep PermGen, too, and remove classes which are no longer used.This option will work only when UseConcMarkSweepGC is also enabled using the below option.
如果您启用 CMSClassUnloadingEnabled,GC 也将清除 PermGen,并删除不再使用的类。此选项仅在使用以下选项启用 UseConcMarkSweepGC 时才有效。
-XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled
-XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled
This parameter indicates whether sweeping of perm gen is enabled. By default this parameter is disabled and so will need to explicitly set this for fine tuning the PermGen issues. This option is removed in Java 6 and so you will need to use -XX:+CMSClassUnloadingEnabled if you are using Java 6 or above. So the options added to resolve the PermGen Space memory issues will look like
该参数表示是否启用了 perm gen 的扫描。默认情况下,此参数是禁用的,因此需要明确设置它以微调 PermGen 问题。Java 6 中删除了此选项,因此如果您使用的是 Java 6 或更高版本,则需要使用 -XX:+CMSClassUnloadingEnabled。所以为解决 PermGen Space 内存问题而添加的选项看起来像
-XX:MaxPermSize=128m -XX:+UseConcMarkSweepGC XX:+CMSClassUnloadingEnabled Memory leaks
-XX:MaxPermSize=128m -XX:+UseConcMarkSweepGC XX:+CMSClassUnloadingEnabled 内存泄漏
And the 2nd reason could be memory leak. How the class definitions that are loaded could can become unused.
第二个原因可能是内存泄漏。加载的类定义如何变得未使用。
Normally in Java, classes are forever. So once the classes are loaded, they stay in memory even if that application is stopped on the server. Dynamic class generation libraries like cglib use lot of PermGen Space since they create a lot of classes dynamically. Heavy use of Proxy classes, which are created synthetically during runtime. It's easy to create new Proxy classes when a single class definition could be reused for multiple instances.
通常在 Java 中,类是永远存在的。因此,一旦加载了类,即使该应用程序在服务器上停止,它们也会保留在内存中。像 cglib 这样的动态类生成库使用了大量的永久代空间,因为它们动态地创建了很多类。大量使用代理类,这些类是在运行时综合创建的。当单个类定义可用于多个实例时,很容易创建新的代理类。
Spring and Hibernate often makes proxies of certain classes. Such proxy classes are loaded by a classloader. The generated class definitions are never discarded causing the permanent heap space to fill up fast.
Spring 和 Hibernate 经常为某些类做代理。此类代理类由类加载器加载。生成的类定义永远不会被丢弃,从而导致永久堆空间快速填满。
For PermGen space issues, you will need identify the cause of leak and fix it. Increasing the PermGen space will not help, it will only delay the issue, since at some point the PermGen space will still be filled up.
对于永久代空间问题,您需要确定泄漏的原因并修复它。增加永久代空间无济于事,它只会延迟问题,因为在某些时候永久代空间仍然会被填满。
You can go through this link: http://wiki.apache.org/tomcat/MemoryLeakProtection
你可以通过这个链接:http: //wiki.apache.org/tomcat/MemoryLeakProtection
Thanks.
谢谢。
回答by sMajeed
Set the -Xms1024M -Xmx4096M -XX:MaxPermSize=4096M
in your tomcat -> launch configuration -> Arguments and you're good to go. The numbers mentioned are just example, you can use that best suits your need.
设置-Xms1024M -Xmx4096M -XX:MaxPermSize=4096M
在你的tomcat - >启动配置- >参数,你是好去。提到的数字只是示例,您可以使用最适合您需要的数字。