From: Charles Nutter Date: 2011-01-11T04:57:19+09:00 Subject: [ruby-core:34311] [Ruby 1.9-Bug#4168] WeakRef is unsafe to use in Ruby 1.9 Issue #4168 has been updated by Charles Nutter. Some clarification about Weak/Soft/Phantom references. * Weak: not considered as references by the GC. Objects that are only weakly referenced could be garbage collected at any time. Weak references can be traversed to reach the object as long as it is referenced. * Soft: Like weak references, but with softer GC characteristics. Specifically, they may survive some number of GC runs before being collected. Useful for weakly-referenced resources that you may leave unreferenced for a while but don't want to end up recreating frequently, such as expensive-to-create data structures. On the JVM, soft references are collected on a schedule based on the size of the heap (i.e. they are not eligible or collection until there's memory pressure or they have been unreferenced for some number of milliseconds per MB of heap). * Phantom: Similar to weak references, but cannot be traversed to get to the original object. Used to implement finalizers in a "pull" model. Where normal finalizers must be executed by the VM, potentially blocking other operations like GC (and usually blocking other finalizers), phantom references can be used with reference queues to implement user-pulled finalization, reducing load on the VM. You associated finalization code with a phantom reference, and when the object it was associated with has been collected it will be pushed onto a reference queue. Periodically, you can pull from that queue to perform finalization in userland. ---------------------------------------- http://redmine.ruby-lang.org/issues/show/4168 ---------------------------------------- http://redmine.ruby-lang.org