Question

I am using Rhino in a project, which requires that I create a number of ScriptableObjects, which are used for a short time, and then discarded. Will doing this create a memory leak?

The code is something like this:

Context cx = ContextFactory.getGlobal.enter();

try {
   for (String script : Scripts.findAll()) {
      Scriptable scope = cx.initStandardObjects();

      // load script into scope, and do something with it.

      // do I need to do any cleanup to for the scope?
   }
} finally {
   Context.exit();
}

Marko's solution is a good one. I tested the scenario with jvisualvm, and found that garbage collection took care of the issue.

Rhino Garbage Collection in action

Was it helpful?

Solution

I believe no cleanup is required, but if you want to dispell any worries, this is very easy to test. Just write an endless loop around the example you have posted and wait for a while. You can monitor the process with jvisualvm as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top