Skip to content

Loading…

JavaProxyClassFactory proxies map keeps runtimes alive #164

Closed
bbrowning opened this Issue · 3 comments

2 participants

@bbrowning

Every time a JavaClassProxy gets created and added to the proxies map in JavaProxyClassFactory, it creates a reference to the JavaClassProxy's Ruby runtime that keeps the runtime from getting garbage collected.

@bbrowning bbrowning added a commit to bbrowning/jruby that referenced this issue
@bbrowning bbrowning Use weak references to Ruby objects in JavaProxyClassFactory (Fixes #164
)

Both the keys and values stored in the proxies list may contain Ruby
objects so use a WeakHashMap to weakly reference the keys and wrap the
values in a WeakReference.
3d31a65
@bbrowning

The referenced commit fixes this issue in my testing. Please look over it to ensure I'm not doing something stupid. I'd make a pull request out of it, but then that would open another issue which is annoying.

@bbrowning

I'm wondering if the use of a WeakHashMap is going to cause items to be evicted from the proxies map too quickly since nothing is holding a strong reference to the key. It probably should be a SoftHashMap, but I don't think such a thing exists in the JDK classes.

@bbrowning

Going to try an alternative approach of storing the JavaProxyClass cache on each runtime vs a static proxies map for all runtimes.

@bbrowning bbrowning added a commit to bbrowning/jruby that referenced this issue
@bbrowning bbrowning Store the JavaProxyClass cache in JavaSupport (refs #164)
This keeps the cache of proxies inside an instance of a Ruby runtime
versus hanging around in a static map in JavaProxyClassFactory.
7cae110
@bbrowning bbrowning added a commit to bbrowning/jruby that referenced this issue
@bbrowning bbrowning Store the JavaProxyClass cache in JavaSupport (fixes #164)
This keeps the cache of proxies inside an instance of a Ruby runtime
versus hanging around in a static map in JavaProxyClassFactory so that
the proxies don't prevent the runtime from being garbage collected.
59a7ed4
@headius headius added a commit that closed this issue
@bbrowning bbrowning Store the JavaProxyClass cache in JavaSupport (fixes #164)
This keeps the cache of proxies inside an instance of a Ruby runtime
versus hanging around in a static map in JavaProxyClassFactory so that
the proxies don't prevent the runtime from being garbage collected.

Signed-off-by: Charles Oliver Nutter <headius@headius.com>
a40de0e
@headius headius closed this in a40de0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.