Issue #4168 has been updated by Charles Nutter.


More comments:

* On JVM, you can only specify a ReferenceQueue to the constructor of a Reference. You cannot change or add queues on already-created references. JRuby would not be able to support adding new reference queues to existing references.
* Soft reference TTL is not configurable from Java APIs directly, and I'm not sure it's possible to query them. Different JVMs use different heuristics for collecting soft references, so there's no consistent definition of what "TTL" actually means. JRuby would not be able to support the gc_ttl method on SoftReference.
* It is not possible to find out how many references have been enqueued on the JVM. You must poll the ReferenceQueue to deal with them as they arrive. I'm not sure of the reason for this limitation, but I assume it's because elements could get enqueued at any time, so the size would be meaningless. JRuby would not be able to support the queued_reference_count method.
* It is also not possible to find out (via normal means) how many weak or soft references are in flight because it does not actually track all of them. JRuby would not be able to support either the weak or soft cached_instance_count methods.

I'd strongly recommend limiting features to those we could implement with the Java reference APIs, since adding APIs we can't support will just cause a lot of code that won't work across implementations.

The docs for the JVM java.lang.ref package are here: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/ref/package-summary.html

I'm very glad to see this API coming together, but I believe care should be taken to avoid exposing details of MRI's GC implementation and avoid adding features that can't be supported on other Ruby VMs.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/4168

----------------------------------------
http://redmine.ruby-lang.org