Module: ObjectSpace
- Defined in:
 - gc.c
 
Class Method Summary collapse
- 
  
    
      ._id2ref(object_id)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Converts an object id to a reference to the object.
 - 
  
    
      .add_finalizer  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
deprecated.
 - 
  
    
      .call_finalizer  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
deprecated.
 - 
  
    
      .define_finalizer(obj, aProc = proc())  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds aProc as a finalizer, to be called after obj was destroyed.
 - 
  
    
      .each_object([) {|obj| ... } ⇒ Fixnum 
    
    
  
  
  
  
  
  
  
  
  
    
Calls the block once for each living, nonimmediate object in this Ruby process.
 - 
  
    
      .finalizers  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
deprecated.
 - 
  
    
      .garbage_collect  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Initiates garbage collection, unless manually disabled.
 - 
  
    
      .remove_finalizer  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
deprecated.
 - 
  
    
      .undefine_finalizer(obj)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Removes all finalizers for obj.
 
Instance Method Summary collapse
- 
  
    
      #_id2ref(object_id)  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
Converts an object id to a reference to the object.
 - 
  
    
      #add_finalizer  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
deprecated.
 - 
  
    
      #call_finalizer  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
deprecated.
 - 
  
    
      #define_finalizer(obj, aProc = proc())  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
Adds aProc as a finalizer, to be called after obj was destroyed.
 - 
  
    
      #each_object([) {|obj| ... } ⇒ Fixnum 
    
    
  
  
  
  
  private
  
  
  
  
    
Calls the block once for each living, nonimmediate object in this Ruby process.
 - 
  
    
      #finalizers  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
deprecated.
 - 
  
    
      #garbage_collect  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
Initiates garbage collection, unless manually disabled.
 - 
  
    
      #remove_finalizer  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
deprecated.
 - 
  
    
      #undefine_finalizer(obj)  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
Removes all finalizers for obj.
 
Class Method Details
._id2ref(object_id) ⇒ Object
Converts an object id to a reference to the object. May not be called on an object id passed as a parameter to a finalizer.
s = "I am a string"                    #=> "I am a string"
r = ObjectSpace._id2ref(s.object_id)   #=> "I am a string"
r == s                                 #=> true
  
      1935 1936 1937  | 
    
      # File 'gc.c', line 1935 static VALUE id2ref(obj, objid) VALUE obj, objid;  | 
  
.add_finalizer ⇒ Object
deprecated
      1704 1705 1706  | 
    
      # File 'gc.c', line 1704 static VALUE add_final(os, block) VALUE os, block;  | 
  
.call_finalizer ⇒ Object
deprecated
      1743 1744 1745  | 
    
      # File 'gc.c', line 1743 static VALUE call_final(os, obj) VALUE os, obj;  | 
  
.define_finalizer(obj, aProc = proc()) ⇒ Object
Adds aProc as a finalizer, to be called after obj was destroyed.
      1780 1781 1782  | 
    
      # File 'gc.c', line 1780 static VALUE define_final(argc, argv, os) int argc;  | 
  
.each_object([) {|obj| ... } ⇒ Fixnum
Calls the block once for each living, nonimmediate object in this Ruby process. If module is specified, calls the block for only those classes or modules that match (or are a subclass of) module. Returns the number of objects found. Immediate objects (Fixnums, Symbols true, false, and nil) are never returned. In the example below, each_object returns both the numbers we defined and several constants defined in the Math module.
a = 102.7
b = 95       # Won't be returned
c = 12345678987654321
count = ObjectSpace.each_object(Numeric) {|x| p x }
puts "Total count: #{count}"
produces:
12345678987654321
102.7
2.71828182845905
3.14159265358979
2.22044604925031e-16
1.7976931348623157e+308
2.2250738585072e-308
Total count: 7
  
      1683 1684 1685  | 
    
      # File 'gc.c', line 1683 static VALUE os_each_obj(argc, argv) int argc;  | 
  
.finalizers ⇒ Object
deprecated
      1732 1733 1734 1735 1736 1737  | 
    
      # File 'gc.c', line 1732
static VALUE
finals()
{
    rb_warn("ObjectSpace::finalizers is deprecated");
    return finalizers;
}
     | 
  
.start ⇒ nil .garbage_collect ⇒ nil .garbage_collect ⇒ nil
Initiates garbage collection, unless manually disabled.
      1418 1419 1420 1421 1422 1423  | 
    
      # File 'gc.c', line 1418
VALUE
rb_gc_start()
{
    rb_gc();
    return Qnil;
}
     | 
  
.remove_finalizer ⇒ Object
deprecated
      1720 1721 1722  | 
    
      # File 'gc.c', line 1720 static VALUE rm_final(os, block) VALUE os, block;  | 
  
.undefine_finalizer(obj) ⇒ Object
Removes all finalizers for obj.
      1761 1762 1763  | 
    
      # File 'gc.c', line 1761 static VALUE undefine_final(os, obj) VALUE os, obj;  | 
  
Instance Method Details
#_id2ref(object_id) ⇒ Object (private)
Converts an object id to a reference to the object. May not be called on an object id passed as a parameter to a finalizer.
s = "I am a string"                    #=> "I am a string"
r = ObjectSpace._id2ref(s.object_id)   #=> "I am a string"
r == s                                 #=> true
  
      1935 1936 1937  | 
    
      # File 'gc.c', line 1935 static VALUE id2ref(obj, objid) VALUE obj, objid;  | 
  
#add_finalizer ⇒ Object (private)
deprecated
      1704 1705 1706  | 
    
      # File 'gc.c', line 1704 static VALUE add_final(os, block) VALUE os, block;  | 
  
#call_finalizer ⇒ Object (private)
deprecated
      1743 1744 1745  | 
    
      # File 'gc.c', line 1743 static VALUE call_final(os, obj) VALUE os, obj;  | 
  
#define_finalizer(obj, aProc = proc()) ⇒ Object (private)
Adds aProc as a finalizer, to be called after obj was destroyed.
      1780 1781 1782  | 
    
      # File 'gc.c', line 1780 static VALUE define_final(argc, argv, os) int argc;  | 
  
#each_object([) {|obj| ... } ⇒ Fixnum (private)
Calls the block once for each living, nonimmediate object in this Ruby process. If module is specified, calls the block for only those classes or modules that match (or are a subclass of) module. Returns the number of objects found. Immediate objects (Fixnums, Symbols true, false, and nil) are never returned. In the example below, each_object returns both the numbers we defined and several constants defined in the Math module.
a = 102.7
b = 95       # Won't be returned
c = 12345678987654321
count = ObjectSpace.each_object(Numeric) {|x| p x }
puts "Total count: #{count}"
produces:
12345678987654321
102.7
2.71828182845905
3.14159265358979
2.22044604925031e-16
1.7976931348623157e+308
2.2250738585072e-308
Total count: 7
  
      1683 1684 1685  | 
    
      # File 'gc.c', line 1683 static VALUE os_each_obj(argc, argv) int argc;  | 
  
#finalizers ⇒ Object (private)
deprecated
      1732 1733 1734 1735 1736 1737  | 
    
      # File 'gc.c', line 1732
static VALUE
finals()
{
    rb_warn("ObjectSpace::finalizers is deprecated");
    return finalizers;
}
     | 
  
#start ⇒ nil (private) #garbage_collect ⇒ nil (private) #garbage_collect ⇒ nil (private)
Initiates garbage collection, unless manually disabled.
      1418 1419 1420 1421 1422 1423  | 
    
      # File 'gc.c', line 1418
VALUE
rb_gc_start()
{
    rb_gc();
    return Qnil;
}
     | 
  
#remove_finalizer ⇒ Object (private)
deprecated
      1720 1721 1722  | 
    
      # File 'gc.c', line 1720 static VALUE rm_final(os, block) VALUE os, block;  | 
  
#undefine_finalizer(obj) ⇒ Object (private)
Removes all finalizers for obj.
      1761 1762 1763  | 
    
      # File 'gc.c', line 1761 static VALUE undefine_final(os, obj) VALUE os, obj;  |