I worked on Grails ( 2.1.0 ) project and after it’s completion found out that Tomcat runs out of memory. After not very sophisticated investigation I found that following lines of code causing memory leak:
def servletContext = ServletContextHolder.servletContext
def config = new ConfigSlurper().parse(servletContext.getResource('/WEB-INF/config.groovy').text)
Once I remove those 2 lines from my code execution, project runs on tomcat with stable memory usage. However if I bring those 2 lines back, memory usage slowly increasing.
I don’t understand why those 2 lines causing memory leak? What is so magical about them? How do I fix it? I need to access resources in the WEB-INF folder.
Thank you.
You say in the comments that
Every time you do
ConfigSlurper.parseit has to compile a Groovy class. Since you are parsing a fixed script (from/WEB-INF/config.groovy) you will get the same result every time, so you should try and find some way to parse the file just once and store the resultingConfigObjectsomewhere that your Quartz job can access it.