Methods

Files

Ref::WeakReference

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


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 = References::WeakReference.new(foo)
ref.object                        # should be foo
ObjectSpace.garbage_collect
ref.object                        # should be nil

Public Class Methods

new(obj) click to toggle source

Create a weak reference to an object.

# File lib/ref/weak_reference.rb, line 16
def initialize(obj)
  raise NotImplementedError.new("This is an abstract class; you must require an implementation")
end

Public Instance Methods

object() click to toggle source

Get the referenced object. If the object has been reclaimed by the garbage collector, then this will return nil.

# File lib/ref/weak_reference.rb, line 22
def object
  raise NotImplementedError.new("This is an abstract class; you must require an implementation")
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.