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:



1935
1936
1937
# File 'gc.c', line 1935

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

.add_finalizerObject

deprecated



1704
1705
1706
# File 'gc.c', line 1704

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

.call_finalizerObject

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

Yields:

  • (obj)

Returns:



1683
1684
1685
# File 'gc.c', line 1683

static VALUE
os_each_obj(argc, argv)
int argc;

.finalizersObject

deprecated



1732
1733
1734
1735
1736
1737
# File 'gc.c', line 1732

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)


1418
1419
1420
1421
1422
1423
# File 'gc.c', line 1418

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

.remove_finalizerObject

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

Returns:



1935
1936
1937
# File 'gc.c', line 1935

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

#add_finalizerObject (private)

deprecated



1704
1705
1706
# File 'gc.c', line 1704

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

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

Yields:

  • (obj)

Returns:



1683
1684
1685
# File 'gc.c', line 1683

static VALUE
os_each_obj(argc, argv)
int argc;

#finalizersObject (private)

deprecated



1732
1733
1734
1735
1736
1737
# File 'gc.c', line 1732

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)


1418
1419
1420
1421
1422
1423
# File 'gc.c', line 1418

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

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