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)
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
.Assuming you've at least 2GB of RAM.
See also:
eclipse.ini
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.
Increase your
MaxPermSize
in youreclipse.ini
. I suggest setting it to 128M or 256M if you're confortable with RAMAlso 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
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):
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!
-Xms64m -Xmx256m
See below images:
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:
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: