Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat/Grails memory leaks

I'm seeing the following in my catalina.out log everytime I undeploy by grails application:

INFO: Closing Spring root WebApplicationContext
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/appName] appears to have started a thread named [PoolCleaner[935209663:1403137427048]] but has failed to stop it. This is very likely to create a memory leak.
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/appName] created a ThreadLocal with key of type [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$1] (value [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$1@7b50a485]) and a value of type [java.util.HashMap] (value [{}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/appName] created a ThreadLocal with key of type [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$2] (value [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$2@6b615702]) and a value of type [java.util.HashMap] (value [{DEFAULT=0}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/appName] created a ThreadLocal with key of type [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$1] (value [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$1@7b50a485]) and a value of type [java.util.HashMap] (value [{}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jun 18, 2014 5:23:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/appName] created a ThreadLocal with key of type [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$2] (value [org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor$2@6b615702]) and a value of type [java.util.HashMap] (value [{DEFAULT=0}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

I actually see over a 100 of the hibernate ones. It seems like there was a memory leak related to domain classes that was fixed in Grails 2.0, but I'm using 2.35. If this is most likely something in my app that is causing these leaks I'd like to know the how to trouble shoot them. Thanks...

like image 753
Jim Sosa Avatar asked Jun 19 '14 17:06

Jim Sosa


People also ask

Where is memory leak in Tomcat?

Go into the heap dump settings for your server Right-click on Tomcat from the sidebar on the left-hand side then select 'Heap Dump'.

How do I find memory leaks in web application?

Start with metrics such as page load times, HTTP request times, and Core Web Vitals – time to the first byte, first contentful paint. If you use Sematext Experience you'll see a number of other useful metrics for your web applications and websites there. However, metrics themselves are only a part of the whole picture.

How does Eclipse detect memory leaks in Java?

Use the Eclipse Memory Analyzer You may need to refresh your project (F5 on the project). Double-click the file and select the Leak Suspects Report. The overview page allows you to start the analysis of the heap dump. The dominator tree gives quickly an overview of the used objects.


1 Answers

Is there any HashMap type field is defined in your domain . And you are populating that domain in your bootstrap.groovy ?

There is some suggestion using HashMap

1. Work with smaller batches of HashMap objects to process at once if possible
2. If you have a lot of duplicate strings, use String.intern() on them before putting them into the HashMap
3. Use the HashMap(int initialCapacity, float loadFactor) constructor to tune for your case

Use hibernate withSession and flush session after x number of save operation. Hibernate session atmost cache 20000-25000 domain object , so you need to flush session after every x amount of save opertaion . flushing session will remove the cache object from hibernate

like image 142
Abhimanyu Avatar answered Oct 19 '22 09:10

Abhimanyu