Type:
Module

The ObjectSpace module contains a number of routines that interact with the garbage collection facility and allow you to traverse all living objects with an iterator.

ObjectSpace also provides support for object finalizers, procs that will be called when a specific object is about to be destroyed by garbage collection.

include ObjectSpace

a = "A"
b = "B"
c = "C"

define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
define_finalizer(a, proc {|id| puts "Finalizer two on #{id}" })
define_finalizer(b, proc {|id| puts "Finalizer three on #{id}" })

produces:

Finalizer three on 537763470
Finalizer one on 537763480
Finalizer two on 537763480
garbage_collect

GC.start â nilgc.garbage_collect â nilObjectSpace.garbage_collect â nil

2015-04-24 13:03:40
undefine_finalizer

ObjectSpace.undefine_finalizer(obj) Class Public methods Removes all finalizers

2015-04-24 13:08:53
count_objects

ObjectSpace.count_objects([result_hash]) â hash Class Public methods Counts

2015-04-24 12:46:54
each_object

ObjectSpace.each_object([module]) {|obj| ... } â fixnumObjectSpace.each_object([module]) â an_enumerator

2015-04-24 12:59:46
_id2ref

ObjectSpace._id2ref(object_id) â an_object Class Public methods Converts an

2015-04-24 12:43:31
define_finalizer

ObjectSpace.define_finalizer(obj, aProc=proc()) Class Public methods Adds aProc

2015-04-24 12:53:44