From: Charles Nutter Date: 2011-01-12T14:15:45+09:00 Subject: [ruby-core:34406] [Ruby 1.9-Bug#4168] WeakRef is unsafe to use in Ruby 1.9 Issue #4168 has been updated by Charles Nutter. A GC callback API? There is no possibility of implementing such an API on JRuby. All the JVMs have different GC implementations, and there's no standard way to have GC callbacks into user code. Is that what you mean? ReferenceQueue is not related to GC implementation at all. A ReferenceQueue is used by the GC to indicate WeakReferences that have had their referenced object collected. They are generally used to do some cleanup logic once WeakReferences no longer reference any object. For example, a WeakHash would register all weak keys with a reference queue, and on each call check to see if any references had been collected. It can then efficiently clean them up, rather than either letting the hash grow endlessly (filling up with dead WeakReference instances) or scanning all instances periodically to see if they are dead. I believe ReferenceQueue would make weak collections trivial to implement from Ruby. See the implementation of IdHash in weakling: https://github.com/headius/weakling/blob/master/lib/weakling/collections.rb ReferenceQueue can also be paired with PhantomReference to implement more efficient finalization, as I described above. ---------------------------------------- http://redmine.ruby-lang.org/issues/show/4168 ---------------------------------------- http://redmine.ruby-lang.org