diff options
author | John Firebaugh <john_firebaugh@us.ibm.com> | 2011-05-17 15:07:32 -0700 |
---|---|---|
committer | John Firebaugh <john_firebaugh@us.ibm.com> | 2011-05-18 11:51:09 -0700 |
commit | 1a9725371131300e3230b4b9c14e669d334f4152 (patch) | |
tree | 71351cad3478b74667a0658cc19badbe61e2ec3f /java/src/json/ext/GeneratorMethods.java | |
parent | 65d259b09e1256e56f301d473a9a083315dc305d (diff) | |
download | json-1a9725371131300e3230b4b9c14e669d334f4152.tar.gz |
Fix memory leak when used from multiple JRuby runtimes.
Diffstat (limited to 'java/src/json/ext/GeneratorMethods.java')
-rw-r--r-- | java/src/json/ext/GeneratorMethods.java | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/java/src/json/ext/GeneratorMethods.java b/java/src/json/ext/GeneratorMethods.java index 28a612d..356f2d0 100644 --- a/java/src/json/ext/GeneratorMethods.java +++ b/java/src/json/ext/GeneratorMethods.java @@ -6,6 +6,7 @@ */ package json.ext; +import java.lang.ref.WeakReference; import org.jruby.Ruby; import org.jruby.RubyArray; import org.jruby.RubyBoolean; @@ -45,9 +46,9 @@ class GeneratorMethods { defineMethods(module, "String", RbString.class); defineMethods(module, "TrueClass", RbTrue.class); - info.stringExtendModule = module.defineModuleUnder("String") - .defineModuleUnder("Extend"); - info.stringExtendModule.defineAnnotatedMethods(StringExtend.class); + info.stringExtendModule = new WeakReference<RubyModule>(module.defineModuleUnder("String") + .defineModuleUnder("Extend")); + info.stringExtendModule.get().defineAnnotatedMethods(StringExtend.class); } /** @@ -140,7 +141,7 @@ class GeneratorMethods { RubyHash result = RubyHash.newHash(runtime); IRubyObject createId = RuntimeInfo.forRuntime(runtime) - .jsonModule.callMethod(context, "create_id"); + .jsonModule.get().callMethod(context, "create_id"); result.op_aset(context, createId, self.getMetaClass().to_s()); ByteList bl = self.getByteList(); @@ -158,7 +159,7 @@ class GeneratorMethods { public static IRubyObject included(ThreadContext context, IRubyObject vSelf, IRubyObject module) { RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime()); - return module.callMethod(context, "extend", info.stringExtendModule); + return module.callMethod(context, "extend", info.stringExtendModule.get()); } } |