Why am I running out of memory when I use Groovy scripts?

JFrog Support
2016-10-06 13:38

There is a known memory leak bug related to Groovy and the ConfigSlurper().parse method.  Increasing MaxPermSize will not solve this issue.

We have reproduced the issue by creating a dummy plugin which calls similar code on every event.

Since you are parsing a fixed script, you will get the same result every time, so you should try and find some way to parse the file just once.

As an example, you might add something like the following code to your script:


def config = ConfigHolder.config class ConfigHolder { static def config= new ConfigSlurper().parse(new File("${System.properties.'artifactory.home'}/etc/plugins/a.properties").toURL()) }


The 'a.properties' in our example would be some static '*.properties' file that you wanted to reference. You would execute the slurp method in a static block outside of the definition so that it is executed only once when loaded into memory. Then you can reference the resulting 'config' object instead of calling slurp multiple times.

You should alter your code to use a similar tactic for any static resources that are referenced in your plugin(s) that are being presently being parsed multiple times.

This groovy plugin handles the issue: (The declaration is on line 132, and the definition at 584)

Here's a link to Stackoverflow regarding the problem.