1 # depends on: module.rb
4 def self.each_object(what=nil, &block)
6 raise ArgumentError, "ObjectSpace doesn't support '#{what}' yet"
9 emit_subclasses(Object, block)
12 def self.emit_subclasses(start, prc)
13 subs = start.__subclasses__
20 count += emit_subclasses(c, prc)
26 # Finalizer support. Uses WeakRef to detect object death.
27 # WeakRef uses the GC to do all the real work.
29 @finalizers = Hash.new
31 def self.define_finalizer(obj, prc=nil, &block)
34 if prc.nil? or !prc.respond_to?(:call)
35 raise ArgumentError, "action must respond to call"
38 @finalizers[obj.object_id] = [WeakRef.new(obj), prc]
42 def self.undefine_finalizer(obj)
43 @finalizers.delete(obj.object_id)
46 def self.run_finalizers
47 @finalizers.each_pair do |key, val|
48 unless val[0].weakref_alive?
49 @finalizers.delete key
55 def self.garbage_collect
60 # Fire up the Thread that will process finalization
61 @thread = Thread.new do
63 Rubinius::ON_GC.receive
64 ObjectSpace.run_finalizers