java.lang.OutOfMemoryError: PermGen space [closed]

2019-01-03 17:39发布

I am getting following error frequently in eclipse IDE 3.2, how could I save the application from these 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)

8条回答
甜甜的少女心
2楼-- · 2019-01-03 17:59

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.

-Xms256m
-Xmx512m
-XX:MaxPermSize=512m

Assuming you've at least 2GB of RAM.

See also:

查看更多
我只想做你的唯一
3楼-- · 2019-01-03 18:00

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.

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-03 18:12

Increase your MaxPermSize in your eclipse.ini. I suggest setting it to 128M or 256M if you're confortable with RAM

-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).

References

查看更多
祖国的老花朵
5楼-- · 2019-01-03 18:18

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:

Just add the following below your -vmargs in eclipse.ini (which is in the same directory as your eclipse binary):

-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.

Hope this helps!

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-03 18:19
  • Click on Server instance.
  • Open Launch Configurations.
  • Increase memory to JVM,in argument tab.

-Xms64m -Xmx256m

See below images:

enter image description here

查看更多
Animai°情兽
7楼-- · 2019-01-03 18:19

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.

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.

So – the java.lang.OutOfMemoryError: PermGen space message indicates that the Permanent Size area in memory is exhausted.

This specific area called PemGen is a dedicated region where Java classes are loaded and stored. This consists of the following:

  • 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:

-XX:MaxPermSize=512m
查看更多
登录 后发表回答