I am using Rhino to embed JavaScript in a Java class. I wanted to create multiple Scriptable scopes using a parent Global scope, but I can't figure out when or how the scopes will be cleaned up (garbage collected). I just want to ensure that I'm not leaking memory with the scopes.
A brief example of what I want to do:
private Global parentScope;
private Context cx;
public MyClass() {
cx = ContextFactory.getGlobal().enterContext();
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_5);
parentScope = new Global(cx);
}
public Scriptable createNewChildScope() {
Scriptable scope = cx.newObject(parentScope);
scope.setPrototype(null);
scope.setParentScope(parentScope);
return scope;
}
Now if I created a bunch of child scopes how and when would they know to be cleaned up? Are they just POJOs that will be cleaned up by whatever GC algorithm is being used, or is there a chance that I'll have a memory leak through the context?
Thank you!