Use weak references to store RhinoCore instances in coreMap to allow them

to be garbage collected.
This commit is contained in:
hns 2004-10-20 14:39:15 +00:00
parent 79f1134805
commit 2a7fa165ec

View file

@ -30,6 +30,7 @@ import helma.scripting.rhino.debug.Tracer;
import org.mozilla.javascript.*; import org.mozilla.javascript.*;
import java.util.*; import java.util.*;
import java.lang.ref.WeakReference;
/** /**
* This is the implementation of ScriptingEnvironment for the Mozilla Rhino EcmaScript interpreter. * This is the implementation of ScriptingEnvironment for the Mozilla Rhino EcmaScript interpreter.
@ -127,12 +128,15 @@ public class RhinoEngine implements ScriptingEngine {
if (coreMap == null) { if (coreMap == null) {
coreMap = new WeakHashMap(); coreMap = new WeakHashMap();
} else { } else {
core = (RhinoCore) coreMap.get(app); WeakReference ref = (WeakReference) coreMap.get(app);
if (ref != null) {
core = (RhinoCore) ref.get();
}
} }
if (core == null) { if (core == null) {
core = new RhinoCore(app); core = new RhinoCore(app);
coreMap.put(app, core); coreMap.put(app, new WeakReference(core));
} }
return core; return core;