A SoftReference 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.
A SoftReference differs from a WeakReference in that the garbage collector is not so eager to reclaim soft references so they should persist longer.
foo = Object.new ref = References::SoftReference.new(foo) ref.object # should be foo ObjectSpace.garbage_collect ref.object # should be foo ObjectSpace.garbage_collect ObjectSpace.garbage_collect ref.object # should be nil
Number of garbage collection cycles after an object is used before a reference to it can be reclaimed.
Get the referenced object. If the object has been reclaimed by the garbage collector, then this will return nil.
# File lib/ref/soft_reference.rb, line 47 def object obj = @weak_reference.object # add a temporary strong reference each time the object is referenced. add_strong_reference(obj) if obj obj end
Generated with the Darkfish Rdoc Generator 2.