Parent

Methods

Files

Class/Module Index [+]

Quicksearch

Concurrent::AbstractThreadLocalVar::WeakReference

@!visibility private


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.

@!visibility private

Attributes

referenced_object_id[R]

The object id of the object being referenced.

Public Class Methods

new(obj) click to toggle source

This implementation of a weak reference simply wraps the standard WeakRef implementation that comes with the Ruby standard library.

# File lib/concurrent/atomic/thread_local_var/weak_key_map.rb, line 38
def initialize(obj)
  @referenced_object_id = obj.__id__
  @ref = ::WeakRef.new(obj)
end

Public Instance Methods

object() click to toggle source
# File lib/concurrent/atomic/thread_local_var/weak_key_map.rb, line 43
def object
  @ref.__getobj__
rescue => e
  # Jruby implementation uses RefError while MRI uses WeakRef::RefError
  if (defined?(RefError) && e.is_a?(RefError)) || (defined?(::WeakRef::RefError) && e.is_a?(::WeakRef::RefError))
    nil
  else
    raise e
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.