tags:

views:

13

answers:

0

I've been testing out JRuby as a possible integrated language to a larger system, but I've run into a problem: heap space. Specifically, JRuby holds on to all the objects it uses when parsing code. I'm not talking about perm space here - there are large quantities of org.jruby.internal.runtime.methods.InterpretedMethod instances building up in my heap, all leftovers from long-ago used ruby code. I found that the org.jruby.Ruby.objectClass was holding these all up in a .methods hashmap. Each entry is indexed by (apparently) the method name, which could be anything in my system, and each entry is a huge bundle of other internal JRuby object. I tried some tests and explored the code but there does not seem to be a clean way of flushing out these objects. The only thing that worked was this:

Ruby.newInstance().useAsGlobalRuntime();
engine = factory.getEngineByName("jruby");

Internally, this resets the singleton to the new instance, hopefully leaving the old one around to finish whatever other processing might be going on. I found that I have to ask for the engine again in order to have it initialized on the next use.

I can't believe that this is the way to do it though, and might even be dangerous to other running threads. It must be a common problem. Anyone know how to get this cleaned up so that the memory can be reclaimed?