Reputation: 7326
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.
Upvotes: 1
Views: 630
Reputation: 122414
You say in the comments that
Code is in the Quartz schedule class. I am parsing it repeatedly once scheduled job executes.
Every time you do ConfigSlurper.parse
it 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 resulting ConfigObject
somewhere that your Quartz job can access it.
Upvotes: 2