Module: ObjectSpace

Defined in:
gc.c

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:



1947
1948
1949
# File 'gc.c', line 1947

static VALUE
id2ref(obj, objid)
VALUE obj, objid;

.add_finalizerObject

deprecated



1716
1717
1718
# File 'gc.c', line 1716

static VALUE
add_final(os, block)
VALUE os, block;

.call_finalizerObject

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 (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

Yields:

  • (obj)

Returns:



1692
1693
1694
# File 'gc.c', line 1692

static VALUE
os_each_obj(argc, argv, os)
int argc;

.finalizersObject

deprecated



1744
1745
1746
1747
1748
1749
# File 'gc.c', line 1744

static VALUE
finals()
{
    rb_warn("ObjectSpace::finalizers is deprecated");
    return finalizers;
}

.startnil .garbage_collectnil .garbage_collectnil

Initiates garbage collection, unless manually disabled.

Overloads:

  • .startnil

    Returns:

    • (nil)
  • .garbage_collectnil

    Returns:

    • (nil)
  • .garbage_collectnil

    Returns:

    • (nil)


1458
1459
1460
1461
1462
1463
# File 'gc.c', line 1458

VALUE
rb_gc_start()
{
    rb_gc();
    return Qnil;
}

.remove_finalizerObject

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

Returns:



1947
1948
1949
# File 'gc.c', line 1947

static VALUE
id2ref(obj, objid)
VALUE obj, objid;

#add_finalizerObject (private)

deprecated



1716
1717
1718
# File 'gc.c', line 1716

static VALUE
add_final(os, block)
VALUE os, block;

#call_finalizerObject (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 (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

Yields:

  • (obj)

Returns:



1692
1693
1694
# File 'gc.c', line 1692

static VALUE
os_each_obj(argc, argv, os)
int argc;

#finalizersObject (private)

deprecated



1744
1745
1746
1747
1748
1749
# File 'gc.c', line 1744

static VALUE
finals()
{
    rb_warn("ObjectSpace::finalizers is deprecated");
    return finalizers;
}

#startnil (private) #garbage_collectnil (private) #garbage_collectnil (private)

Initiates garbage collection, unless manually disabled.

Overloads:

  • #startnil

    Returns:

    • (nil)
  • #garbage_collectnil

    Returns:

    • (nil)
  • #garbage_collectnil

    Returns:

    • (nil)


1458
1459
1460
1461
1462
1463
# File 'gc.c', line 1458

VALUE
rb_gc_start()
{
    rb_gc();
    return Qnil;
}

#remove_finalizerObject (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;