Kotlin Script Engine Memory Leak

Hello!
I wrote a small test application, that execute a simple script (just print a line (println (“test”))).
I looped on the execution of this script. And after several thousand iterations (~ 10 000) the application fell with OutOfMemory.

Sample code

System.setProperty("idea.io.use.fallback", "true")
val e2 = KotlinScriptEngineFactory().scriptEngine
var i = 0
while (i<100_000_000) {
    println("i = $i")
    val bindings = SimpleBindings()
    bindings["srv"] = TestService();
    e2.eval("""
    println("test")
""".trimIndent(), bindings)
    i++

}

What am I doing wrong? may need to call some resource freeing method?
Nobody stalled with memory leaks when using a cotlin script engine?
Sorry for my English

4 Likes

Thanks for the report, I submitted an issue at https://youtrack.jetbrains.com/issue/KT-32020, please follow it for updates.

1 Like