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
1947 1948 1949 |
# File 'gc.c', line 1947 static VALUE id2ref(obj, objid) VALUE obj, objid; |
.add_finalizer ⇒ Object
deprecated
1716 1717 1718 |
# File 'gc.c', line 1716 static VALUE add_final(os, block) VALUE os, block; |
.call_finalizer ⇒ Object
deprecated
1755 1756 1757 |
# File 'gc.c', line 1755 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.
1792 1793 1794 |
# File 'gc.c', line 1792 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 (Fixnum
s, Symbol
s 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
1692 1693 1694 |
# File 'gc.c', line 1692 static VALUE os_each_obj(argc, argv, os) int argc; |
.finalizers ⇒ Object
deprecated
1744 1745 1746 1747 1748 1749 |
# File 'gc.c', line 1744 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.
1458 1459 1460 1461 1462 1463 |
# File 'gc.c', line 1458 VALUE rb_gc_start() { rb_gc(); return Qnil; } |
.remove_finalizer ⇒ Object
deprecated
1732 1733 1734 |
# File 'gc.c', line 1732 static VALUE rm_final(os, block) VALUE os, block; |
.undefine_finalizer(obj) ⇒ Object
Removes all finalizers for obj.
1773 1774 1775 |
# File 'gc.c', line 1773 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
1947 1948 1949 |
# File 'gc.c', line 1947 static VALUE id2ref(obj, objid) VALUE obj, objid; |
#add_finalizer ⇒ Object (private)
deprecated
1716 1717 1718 |
# File 'gc.c', line 1716 static VALUE add_final(os, block) VALUE os, block; |
#call_finalizer ⇒ Object (private)
deprecated
1755 1756 1757 |
# File 'gc.c', line 1755 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.
1792 1793 1794 |
# File 'gc.c', line 1792 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 (Fixnum
s, Symbol
s 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
1692 1693 1694 |
# File 'gc.c', line 1692 static VALUE os_each_obj(argc, argv, os) int argc; |
#finalizers ⇒ Object (private)
deprecated
1744 1745 1746 1747 1748 1749 |
# File 'gc.c', line 1744 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.
1458 1459 1460 1461 1462 1463 |
# File 'gc.c', line 1458 VALUE rb_gc_start() { rb_gc(); return Qnil; } |
#remove_finalizer ⇒ Object (private)
deprecated
1732 1733 1734 |
# File 'gc.c', line 1732 static VALUE rm_final(os, block) VALUE os, block; |
#undefine_finalizer(obj) ⇒ Object (private)
Removes all finalizers for obj.
1773 1774 1775 |
# File 'gc.c', line 1773 static VALUE undefine_final(os, obj) VALUE os, obj; |