Hello,
im using Groovy in a Java Applikation through ScriptEngineManager.
Im calling Groovy scripts every few seconds and im experiencing a
Memory Leak in my applikation.
To demostrate you can use this examples:
With Memory Leak:
public class GroovyLauncherWithLeak {
public static void main(String[] args) throws InterruptedException,
ScriptException {
ScriptEngineManager manager = new ScriptEngineManager();
engine = manager.getEngineByName("groovy");
int counter;
while (true) {
StringBuilder sb = new StringBuilder();
sb.append("return \"hello
").append(counter).append(" \"");
long start = System.currentTimeMillis();
engine.eval(sb.toString()9;
System.out.println("Duration: " +
(System.currentTimeMillis() -
start) + "ms" );
Thread.sleep(50L);
counter += 1;
}
}
}
Run this an watch the JVM growing till OOM (PermGenSize)
Heapdump shows as much Instances of a Script Object how often this
loop was running.
Without Memory Leak:
public class GroovyLauncherWithLeak {
private static ScriptEngineManager manager = new
ScriptEngineManager();
private static ScriptEngine engine =
manager.getEngineByName("groovy");
public static void main(String[] args) throws InterruptedException,
ScriptException {
int counter;
while (true) {
StringBuilder sb = new StringBuilder();
sb.append("return \"hello
").append(counter).append(" \"");
long start = System.currentTimeMillis();
engine.eval(sb.toString()9;
System.out.println("Duration: " +
(System.currentTimeMillis() -
start) + "ms" );
Thread.sleep(50L);
counter += 1;
}
}
}
From my point of view there must be a way to specify how ScriptEnginge
caches the compiled classes. Any Ideas ?
Greetings
Stefan Majer
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email