class Ref::WeakReference

A WeakReference represents a reference to an object that is not seen by the tracing phase of the garbage collector. This allows the referenced object to be garbage collected as if nothing is referring to it.

Example usage:

foo = Object.new
ref = Ref::WeakReference.new(foo)
ref.object                        # should be foo
ObjectSpace.garbage_collect
ref.object                        # should be nil

This is a pure ruby implementation of a weak reference. It is much more efficient than the WeakRef implementation bundled in MRI 1.8 and 1.9 subclass Delegator which is very heavy to instantiate and utilizes a because it does not fair amount of memory under Ruby 1.8.