JavaProxyClassFactory proxies map keeps runtimes alive #164

Closed
bbrowning opened this Issue May 9, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@bbrowning
Contributor

bbrowning commented May 9, 2012

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 added a commit to bbrowning/jruby that referenced this issue May 15, 2012

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.
@bbrowning

This comment has been minimized.

Show comment
Hide comment
@bbrowning

bbrowning May 15, 2012

Contributor

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.

Contributor

bbrowning commented May 15, 2012

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

This comment has been minimized.

Show comment
Hide comment
@bbrowning

bbrowning May 15, 2012

Contributor

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.

Contributor

bbrowning commented May 15, 2012

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

This comment has been minimized.

Show comment
Hide comment
@bbrowning

bbrowning May 15, 2012

Contributor

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

Contributor

bbrowning commented May 15, 2012

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

bbrowning added a commit to bbrowning/jruby that referenced this issue May 15, 2012

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.

bbrowning added a commit to bbrowning/jruby that referenced this issue May 15, 2012

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.

@headius headius closed this in a40de0e May 15, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment