Subj : Re: Memory leak with Rhino class loader? To : netscape.public.mozilla.jseng From : tdwang@yahoo.com (Tom) Date : Thu Jan 23 2003 04:04 pm Igor, Thank you for your reply! SetOptimizationLevel(-1) did the trick. I have a follow up question but I'll post it under a seperate subject. -Tom Igor Bukanov wrote in message news:<3E2FBB77.50704@icesoft.no>... > 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 .