Groovy generated classes aren't garbage collected

Description

Every time a script is evaluated PermGen is keeping references to the classes created by Groovy, causing inevitably an OutOfMemoryError when working with heavy load. As stated in GROOVY-5187 we can see it is a Groovy issue. The last was reverted by GROOVY-5786 because of regression, but includes a workaroud by passing one setting to ScriptContext. Here JSR 223 Scripting with Groovy explains how.

I tried the solution just by passing this setting (scriptEngine.getContext().setAttribute("#jsr223.groovy.engine.keep.globals", "weak", ScriptContext.ENGINE_SCOPE); ) before each evaluation of script in ScriptingEngines.java but it didn't work, as I could see monitoring the JVM. Then I used the solution of the attached patch, just keeping a Map of ScriptEngine and configure each once. I don't know if this is a good approach, any hints will be appreciated.

Environment

IBM(R) 32-bit SDK for Windows(R), Java(TM) Technology Edition, Version 6

Assignee

Frederik Heremans

Reporter

Alan Artigao

Labels

None

Components

Fix versions

Priority

Major
Configure