Subj : Memory leak with Rhino class loader? To : netscape.public.mozilla.jseng From : tdwang@yahoo.com (Tom) Date : Wed Jan 22 2003 07:33 pm 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? Thanks in advance! -Tom .