Subj : Re: Memory leak with Rhino class loader? To : Tom From : Igor Bukanov Date : Thu Jan 23 2003 10:52 am Tom wrote: > Hello, > > I really need some pointer on this so any help is greatly appreciated! > > I have a servlet running in Tomcat: > > public void doGet(HttpServletRequest request, HttpServletResponse > response) throws ServletException, IOException { > Context cx = Context.enter(); > try { > Scriptable scope = cx.initStandardObjects(null); > String src = "function foo(i) {return i;}"; > int count = 1; > while (true) { > Function function = cx.compileFunction(scope, src, > "foo", 1, null); > Object[] args = new Object[1]; > args[0] = String.valueOf(count++); > Object result = function.call(cx, scope, null, args); > System.out.println("result=" + result.toString()); > if (count > 100) { > break; > } > } > } catch (Exception e) { > e.printStackTrace(); > } finally { > cx.exit(); > } > } > > I found out that during each compilation Rhino creates a new > DefiningClassLoader and uses it to load the compiled class. So after > 100 loops there will be 100 java classes (org.mozilla.gen.cxx) and 100 > new class loaders. But these new classes never get garbage collected > even after servlet exits. So the memory just keeps piling up. Is > this a bug in Rhino or Tomcat, or am I missing something? This is a bug in JVM that failed to collect loaded classes. Which version do you use? For details, see http://bugzilla.mozilla.org/show_bug.cgi?id=64397 Try to use the interpreter mode which does not generate any Java classes that may even be faster if you always need to compile a function before calling it: Context cx = Context.enter(); try { cx.setOptimizationLevel(-1); .... Regards, Igor .