java.lang.OutOfMemoryError: PermGen space [closed]
Asked Answered
A

8

35

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)
Accouchement answered 18/9, 2010 at 23:58 Comment(2)
possible duplicate of Eclipse:java.lang.OutOfMemoryError: PermGen spacePitfall
@You marked this as a duplicate of the three years younger question. Better change your target.Marchland
M
36

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:

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

Marchland answered 30/5, 2012 at 10:39 Comment(3)
-XX:MaxPermSize=512m is more than enough.Rosettarosette
@Rosettarosette There was one guy already who told that 640k memory is enough for everything... Don't think that the whole world is limited to your tasks. We are talking on writing wizards - launching application in Eclipse launched in Eclipse. Even in 2012 512M was definitely not enough. Now Eclipses became bigger and it could take even more memory.Marchland
-Xms120m -Xmx2048m -XX:MaxPermSize=1024m worksPartheniaparthenocarpy
M
20

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:

Mcburney answered 19/9, 2010 at 0:8 Comment(2)
It seems like your solution is only a temp solution, how to fix the underlaying problem, and use less permgen space?Adali
@Grae: profile the code and improve it. If it cannot be improved and those memory allocations are simply mandatory in order to run your code, then just give it more memory. Simple as that.Mcburney
B
19
  • Click on Server instance.
  • Open Launch Configurations.
  • Increase memory to JVM,in argument tab.

-Xms64m -Xmx256m

See below images:

enter image description here

Bisulcate answered 29/5, 2013 at 9:57 Comment(0)
S
5

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
Stanislaw answered 16/4, 2014 at 7:56 Comment(1)
why 512m? Is there any reason why many examples give that size?Ailing
N
2

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!

Nestling answered 19/9, 2010 at 0:9 Comment(0)
M
2

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

Discussion of an example of how a Permgen OOM error can occur: 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

Martinmartina answered 19/9, 2010 at 0:34 Comment(0)
R
1

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

Ryannryazan answered 19/9, 2010 at 0:14 Comment(0)
O
1

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.

Osteophyte answered 12/1, 2013 at 4:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.