123456789_123456789_123456789_123456789_123456789_

Module: ObjectSpace

Overview

The objspace library extends the ObjectSpace module and adds several methods to get internal statistic information about object/memory management.

You need to require 'objspace' to use this extension module.

Generally, you SHOULD NOT use this library if you do not know about the MRI implementation. Mainly, this library is for (memory) profiler developers and MRI developers who need to know about MRI memory usage.

Class Method Summary

Class Method Details

._dump(obj, output) (mod_func)

This method is for internal use only.
[ GitHub ]

  
# File 'ext/objspace/objspace_dump.c', line 797

static VALUE
objspace_dump(VALUE os, VALUE obj, VALUE output)
{
    VALUE args[2];
    args[0] = obj;
    args[1] = output;
    return rb_vm_lock_with_barrier(dump_locked, (void*)args);
}

._dump_all(output, full, since, shapes) (mod_func)

This method is for internal use only.
[ GitHub ]

  
# File 'ext/objspace/objspace_dump.c', line 882

static VALUE
objspace_dump_all(VALUE os, VALUE output, VALUE full, VALUE since, VALUE shapes)
{
    VALUE args[4];
    args[0] = output;
    args[1] = full;
    args[2] = since;
    args[3] = shapes;
    return rb_vm_lock_with_barrier(dump_all_locked, (void*)args);
}

._dump_shapes(output, shapes) (mod_func)

This method is for internal use only.
[ GitHub ]

  
# File 'ext/objspace/objspace_dump.c', line 909

static VALUE
objspace_dump_shapes(VALUE os, VALUE output, VALUE shapes)
{
    VALUE args[2];
    args[0] = output;
    args[1] = shapes;
    return rb_vm_lock_with_barrier(dump_shapes_locked, (void*)args);
}

.allocation_class_path(object) ⇒ String (mod_func)

Returns the class for the given object.

class A
  def foo
    ObjectSpace::trace_object_allocations do
      obj = Object.new
      p "#{ObjectSpace::allocation_class_path(obj)}"
    end
  end
end

A.new.foo #=> "Class"

See .trace_object_allocations for more information and examples.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 505

static VALUE
allocation_class_path(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);

    if (info && info->class_path) {
        return rb_str_new2(info->class_path);
    }
    else {
        return Qnil;
    }
}

.allocation_generation(object) ⇒ Integer? (mod_func)

Returns garbage collector generation for the given object.

class B
  include ObjectSpace

  def foo
    trace_object_allocations do
      obj = Object.new
      p "Generation is #{allocation_generation(obj)}"
    end
  end
end

B.new.foo #=> "Generation is 3"

See .trace_object_allocations for more information and examples.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 570

static VALUE
allocation_generation(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);
    if (info) {
        return SIZET2NUM(info->generation);
    }
    else {
        return Qnil;
    }
}

.allocation_method_id(object) ⇒ String (mod_func)

Returns the method identifier for the given object.

class A
  include ObjectSpace

  def foo
    trace_object_allocations do
      obj = Object.new
      p "#{allocation_class_path(obj)}##{allocation_method_id(obj)}"
    end
  end
end

A.new.foo #=> "Class#new"

See .trace_object_allocations for more information and examples.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 538

static VALUE
allocation_method_id(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);
    if (info) {
        return info->mid;
    }
    else {
        return Qnil;
    }
}

.allocation_sourcefile(object) ⇒ String (mod_func)

Returns the source file origin from the given object.

See .trace_object_allocations for more information and examples.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 454

static VALUE
allocation_sourcefile(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);

    if (info && info->path) {
        return rb_str_new2(info->path);
    }
    else {
        return Qnil;
    }
}

.allocation_sourceline(object) ⇒ Integer (mod_func)

Returns the original line from source for from the given object.

See .trace_object_allocations for more information and examples.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 474

static VALUE
allocation_sourceline(VALUE self, VALUE obj)
{
    struct allocation_info *info = lookup_allocation_info(obj);

    if (info) {
        return INT2FIX(info->line);
    }
    else {
        return Qnil;
    }
}

.count_imemo_objects(result_hash = nil) ⇒ Hash (mod_func)

Returns a hash containing the number of objects for each T_IMEMO type. The keys are Symbol objects of the T_IMEMO type name. T_IMEMO objects are Ruby internal objects that are not visible to Ruby programs.

ObjectSpace.count_imemo_objects
# => {imemo_callcache: 5482, imemo_constcache: 1258, imemo_ment: 13906, ... }

If the optional argument result_hash is given, it is overwritten and returned. This is intended to avoid the probe effect.

This method is intended for developers interested in performance and memory usage of Ruby programs. The contents of the returned hash is implementation specific and may change in the future.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 455

static VALUE
count_imemo_objects(int argc, VALUE *argv, VALUE self)
{
    VALUE hash = setup_hash(argc, argv);

    if (imemo_type_ids[0] == 0) {
#define INIT_IMEMO_TYPE_ID(n) (imemo_type_ids[n] = rb_intern_const(#n))
        INIT_IMEMO_TYPE_ID(imemo_env);
        INIT_IMEMO_TYPE_ID(imemo_cref);
        INIT_IMEMO_TYPE_ID(imemo_svar);
        INIT_IMEMO_TYPE_ID(imemo_throw_data);
        INIT_IMEMO_TYPE_ID(imemo_ifunc);
        INIT_IMEMO_TYPE_ID(imemo_memo);
        INIT_IMEMO_TYPE_ID(imemo_ment);
        INIT_IMEMO_TYPE_ID(imemo_iseq);
        INIT_IMEMO_TYPE_ID(imemo_tmpbuf);
        INIT_IMEMO_TYPE_ID(imemo_cvar_entry);
        INIT_IMEMO_TYPE_ID(imemo_callinfo);
        INIT_IMEMO_TYPE_ID(imemo_callcache);
        INIT_IMEMO_TYPE_ID(imemo_constcache);
        INIT_IMEMO_TYPE_ID(imemo_fields);
        INIT_IMEMO_TYPE_ID(imemo_subclasses);
        INIT_IMEMO_TYPE_ID(imemo_cdhash);
#undef INIT_IMEMO_TYPE_ID
    }

    each_object_with_flags(count_imemo_objects_i, (void *)hash);

    return hash;
}

.count_objects_size(result_hash = {}) ⇒ result_hash (mod_func)

Counts objects size (in bytes) for each type.

Note that the returned size may not be accurate, so it should only be used as a hint. Specifically, the size for T_DATA may be inaccurate because these are custom objects defined in Ruby and native extensions and so they may not accurately report their memory size.

It returns a hash that looks like:

{TOTAL: 1461154, T_CLASS: 158280, T_MODULE: 20672, T_STRING: 527249, ...}

The contents of the returned hash are implementation specific and may be changed in future versions without notice.

If the optional argument, result_hash, is given, it is overwritten and returned. This is intended to avoid the probe effect.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 262

static VALUE
count_objects_size(int argc, VALUE *argv, VALUE os)
{
    size_t counts[T_MASK+1];
    size_t total = 0;
    enum ruby_value_type i;
    VALUE hash = setup_hash(argc, argv);

    for (i = 0; i <= T_MASK; i++) {
        counts[i] = 0;
    }

    each_object_with_flags(cos_i, &counts[0]);

    for (i = 0; i <= T_MASK; i++) {
        if (counts[i]) {
            VALUE type = type2sym(i);
            total += counts[i];
            rb_hash_aset(hash, type, SIZET2NUM(counts[i]));
        }
    }
    rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total));
    return hash;
}

.count_symbols(result_hash = nil) ⇒ Hash (mod_func)

Returns a hash containing the number of objects for each Symbol type.

The types of Symbols are the following:

  • mortal_dynamic_symbol: Symbols that are garbage collectable.
  • immortal_dynamic_symbol: Symbols that are objects allocated from the garbage collector, but are not garbage collectable.
  • immortal_static_symbol: Symbols that are not allocated from the garbage collector, and are thus not garbage collectable.
  • immortal_symbol: the sum of immortal_dynamic_symbol and immortal_static_symbol.

If the optional argument result_hash is given, it is overwritten and returned. This is intended to avoid the probe effect.

This method is intended for developers interested in performance and memory usage of Ruby programs. The contents of the returned hash is implementation specific and may change in the future.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 335

static VALUE
count_symbols(int argc, VALUE *argv, VALUE os)
{
    struct dynamic_symbol_counts dynamic_counts = {0, 0};
    VALUE hash = setup_hash(argc, argv);

    size_t immortal_symbols = rb_sym_immortal_count();
    each_object_with_flags(cs_i, &dynamic_counts);

    rb_hash_aset(hash, ID2SYM(rb_intern("mortal_dynamic_symbol")),   SIZET2NUM(dynamic_counts.mortal));
    rb_hash_aset(hash, ID2SYM(rb_intern("immortal_dynamic_symbol")), SIZET2NUM(dynamic_counts.immortal));
    rb_hash_aset(hash, ID2SYM(rb_intern("immortal_static_symbol")),  SIZET2NUM(immortal_symbols - dynamic_counts.immortal));
    rb_hash_aset(hash, ID2SYM(rb_intern("immortal_symbol")),         SIZET2NUM(immortal_symbols));

    return hash;
}

.count_tdata_objects(result_hash = nil) ⇒ Hash (mod_func)

Returns a hash containing the number of objects for each T_DATA type. The keys are Class objects when the T_DATA object has an associated class, or Symbol objects of the name defined in the rb_data_type_struct for internal T_DATA objects.

ObjectSpace.count_tdata_objects
# => {RBS::Location => 39255, marshal_compat_table: 1, Encoding => 103, mutex: 1, ... }

If the optional argument result_hash is given, it is overwritten and returned. This is intended to avoid the probe effect.

This method is intended for developers interested in performance and memory usage of Ruby programs. The contents of the returned hash is implementation specific and may change in the future.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 401

static VALUE
count_tdata_objects(int argc, VALUE *argv, VALUE self)
{
    VALUE hash = setup_hash(argc, argv);
    each_object_with_flags(cto_i, (void *)hash);
    return hash;
}

.dump(obj, output: :string) (mod_func)

Dump the contents of a ruby object as JSON.

output can be one of: :stdout, :file, :string, or IO object.

  • :file means dumping to a tempfile and returning corresponding File object;
  • :stdout means printing the dump and returning nil;
  • :string means returning a string with the dump;
  • if an instance of IO object is provided, the output goes there, and the object is returned.

This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.

[ GitHub ]

  
# File 'ext/objspace/lib/objspace.rb', line 28

def dump(obj, output: :string)
  out = case output
  when :file, nil
    require 'tempfile'
    Tempfile.create(%w(rubyobj .json))
  when :stdout
    STDOUT
  when :string
    +''
  when IO
    output
  else
    raise ArgumentError, "wrong output option: #{output.inspect}"
  end

  ret = _dump(obj, out)
  return nil if output == :stdout
  ret
end

.dump_all(output: :file, full: false, since: nil, shapes: true) (mod_func)

Dump the contents of the ruby heap as JSON.

output argument is the same as for #dump.

full must be a boolean. If true, all heap slots are dumped including the empty ones (T_NONE).

since must be a non-negative integer or nil.

If since is a positive integer, only objects of that generation and newer generations are dumped. The current generation can be accessed using GC.count. Objects that were allocated without object allocation tracing enabled are ignored. See .trace_object_allocations for more information and examples.

If since is omitted or is nil, all objects are dumped.

shapes must be a boolean or a non-negative integer.

If shapes is a positive integer, only shapes newer than the provided shape id are dumped. The current shape_id can be accessed using RubyVM.stat(:next_shape_id).

If shapes is false, no shapes are dumped.

To only dump objects allocated past a certain point you can combine since and shapes:

ObjectSpace.trace_object_allocations
GC.start
gc_generation = GC.count
shape_generation = RubyVM.stat(:next_shape_id)
call_method_to_instrument
ObjectSpace.dump_all(since: gc_generation, shapes: shape_generation)

This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.

[ GitHub ]

  
# File 'ext/objspace/lib/objspace.rb', line 84

def dump_all(output: :file, full: false, since: nil, shapes: true)
  out = case output
  when :file, nil
    require 'tempfile'
    Tempfile.create(%w(rubyheap .json))
  when :stdout
    STDOUT
  when :string
    +''
  when IO
    output
  else
    raise ArgumentError, "wrong output option: #{output.inspect}"
  end

  shapes = 0 if shapes == true
  ret = _dump_all(out, full, since, shapes)
  return nil if output == :stdout
  ret
end

.dump_shapes(output: :file, since: 0) (mod_func)

Dump the contents of the ruby shape tree as JSON.

output argument is the same as for #dump.

If since is a positive integer, only shapes newer than the provided shape id are dumped. The current shape_id can be accessed using RubyVM.stat(:next_shape_id).

This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.

[ GitHub ]

  
# File 'ext/objspace/lib/objspace.rb', line 116

def dump_shapes(output: :file, since: 0)
  out = case output
  when :file, nil
    require 'tempfile'
    Tempfile.create(%w(rubyshapes .json))
  when :stdout
    STDOUT
  when :string
    +''
  when IO
    output
  else
    raise ArgumentError, "wrong output option: #{output.inspect}"
  end

  ret = _dump_shapes(out, since)
  return nil if output == :stdout
  ret
end

.internal_class_of(obj) ⇒ class, module (mod_func)

Returns the real class of obj, which may differ from the class returned by Object#class.

Ruby inserts hidden classes into an object's ancestry, such as a singleton class or an included module's iclass. Object#class skips over these, but this method returns the first one, including any hidden class:

require 'objspace'

s = "x"
def s.foo; end                     # gives {s} a singleton class
s.class                            # => String
ObjectSpace.internal_class_of(s)   # => #<Class:#<String:0x000000012574c1f8>>

obj may be an ::ObjectSpace::InternalObjectWrapper, in which case the class of the wrapped internal object is returned.

Note that you should not use this method in your application.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 760

static VALUE
objspace_internal_class_of(VALUE self, VALUE obj)
{
    VALUE klass;

    if (rb_typeddata_is_kind_of(obj, &iow_data_type)) {
        obj = (VALUE)DATA_PTR(obj);
    }

    if (RB_TYPE_P(obj, T_IMEMO)) {
        return Qnil;
    }
    else {
        klass = CLASS_OF(obj);
        return wrap_klass_iow(klass);
    }
}

.internal_super_of(cls) ⇒ class, module (mod_func)

Returns the immediate superclass of cls, including any hidden class such as an included module's iclass.

Unlike Class#superclass, this does not skip over the iclasses that Ruby inserts for included modules:

require 'objspace'

module M; end
class A; include M; end
A.superclass                       # => Object
ObjectSpace.internal_super_of(A)   # => #<InternalObject:0x... T_ICLASS>

cls must be a Class or Module, or an ::ObjectSpace::InternalObjectWrapper that wraps one.

Note that you should not use this method in your application.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 802

static VALUE
objspace_internal_super_of(VALUE self, VALUE obj)
{
    VALUE super;

    if (rb_typeddata_is_kind_of(obj, &iow_data_type)) {
        obj = (VALUE)DATA_PTR(obj);
    }

    switch (OBJ_BUILTIN_TYPE(obj)) {
      case T_MODULE:
      case T_CLASS:
      case T_ICLASS:
        super = rb_class_super_of(obj);
        break;
      default:
        rb_raise(rb_eArgError, "class or module is expected");
    }

    return wrap_klass_iow(super);
}

.memsize_of(obj) ⇒ Integer (mod_func)

Returns the amount of memory in bytes consumed by obj.

The returned size includes the slot that obj occupies plus any memory that obj allocates outside of that slot, such as the storage backing a large String, Array, or Hash:

require 'objspace'

ObjectSpace.memsize_of("small")        # => 40
ObjectSpace.memsize_of("a" * 1000)     # => 1041
ObjectSpace.memsize_of([1, 2, 3])      # => 40
ObjectSpace.memsize_of(Array.new(100)) # => 840

Special constants such as true, false, nil, small integers, and some symbols do not occupy a slot, so their size is reported as 0:

ObjectSpace.memsize_of(true)   # => 0
ObjectSpace.memsize_of(42)     # => 0

The returned size is only a hint and may be an underestimate, since it does not account for all of the memory that obj references. In particular, the size of a T_DATA object (an object implemented in C, such as one defined by a C extension) may not be reported correctly.

This method is only expected to work with CRuby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 62

static VALUE
memsize_of_m(VALUE self, VALUE obj)
{
    return SIZET2NUM(rb_obj_memsize_of(obj));
}

.memsize_of_all(klass = nil) ⇒ Integer (mod_func)

Returns the total memory size of all living objects in bytes.

ObjectSpace.memsize_of_all # => 12502001

If klass is given (which must be a Class or Module), returns the total memory size of objects whose class is, or is a subclass, of klass.

class MyClass; end
ObjectSpace.memsize_of_all(MyClass) # => 0
o = MyClass.new
ObjectSpace.memsize_of_all(MyClass) # => 40

Note that the value returned may be an underestimate of the actual amount of memory used. Therefore, the value returned should only be used as a hint, rather than a source of truth. In particular, the size of T_DATA objects may not be correct.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 147

static VALUE
memsize_of_all_m(int argc, VALUE *argv, VALUE self)
{
    struct total_data data = {0, 0};

    if (argc > 0) {
        rb_scan_args(argc, argv, "01", &data.klass);
        if (!NIL_P(data.klass)) rb_obj_is_kind_of(Qnil, data.klass);
    }

    each_object_with_flags(total_i, &data);
    return SIZET2NUM(data.total);
}

.reachable_objects_from(obj) ⇒ Array? (mod_func)

Returns all reachable objects from obj as an array:

ObjectSpace.reachable_objects_from(['a', 'b', 'c'])
#=> [Array, 'a', 'b', 'c']

The returned array is deduplicated, meaning that if obj refers to another object more than once, it will only be added to the array once:

ObjectSpace.reachable_objects_from([v = 'a', v, v])
#=> [Array, 'a']

Returns nil if obj is not a markable object (i.e. non-heap managed) object. Non-markable objects include true, false, nil, certain symbols, small integers, and floats:

ObjectSpace.reachable_objects_from(1)
#=> nil

All references to internal objects in the returned array are wrapped using ::ObjectSpace::InternalObjectWrapper objects. This object contains a reference to the internal object and the type of the object can be accessed using the InternalObjectWrapper#type method.

If obj is instance of ::ObjectSpace::InternalObjectWrapper, then this method returns all reachable object from the internal object.

This method is useful for debugging purposes, such as finding memory leaks.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 609

static VALUE
reachable_objects_from(VALUE self, VALUE obj)
{
    if (!RB_SPECIAL_CONST_P(obj)) {
        struct rof_data data;

        if (rb_typeddata_is_kind_of(obj, &iow_data_type)) {
            obj = (VALUE)DATA_PTR(obj);
        }

        data.refs = rb_obj_hide(rb_ident_hash_new());
        data.values = rb_ary_new();

        rb_objspace_reachable_objects_from(obj, reachable_object_from_i, &data);

        return data.values;
    }
    else {
        return Qnil;
    }
}

.reachable_objects_from_rootHash (mod_func)

Returns a hash of objects directly reachable from the VM roots, grouped by the root that reaches them.

The roots are the entry points the garbage collector starts from when it marks live objects, such as the virtual machine and the global variable table. The keys of the returned hash are strings naming each root, and each value is an array of the objects reachable from that root:

require 'objspace'

reachable = ObjectSpace.reachable_objects_from_root
reachable.keys           # => ["vm", "global_tbl", "machine_context", "global_symbols"]
reachable.values.first   # => [#<Ractor:#1 running>, ...]

The returned hash compares its keys by identity, so it cannot be indexed with a string literal; iterate over it (or over its #values) instead.

Any reference to an internal object is wrapped in an ::ObjectSpace::InternalObjectWrapper object.

This method is useful for debugging the object graph, for example when tracking down the cause of a memory leak.

This method is only expected to work with C Ruby.

[ GitHub ]

  
# File 'ext/objspace/objspace.c', line 707

static VALUE
reachable_objects_from_root(VALUE self)
{
    struct rofr_data data;
    VALUE hash = data.categories = rb_ident_hash_new();
    data.last_category = 0;

    rb_objspace_reachable_objects_from_root(reachable_object_from_root_i, &data);
    rb_hash_foreach(hash, collect_values_of_values, hash);

    return hash;
}

.trace_object_allocations (mod_func)

Starts tracing object allocations from the ObjectSpace extension module.

For example:

require 'objspace'

class C
  include ObjectSpace

  def foo
    trace_object_allocations do
      obj = Object.new
      p "#{allocation_sourcefile(obj)}:#{allocation_sourceline(obj)}"
    end
  end
end

C.new.foo #=> "objtrace.rb:8"

This example has included the ObjectSpace module to make it easier to read, but you can also use the .trace_object_allocations notation (recommended).

Note that this feature introduces a huge performance decrease and huge memory consumption.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 370

static VALUE
trace_object_allocations(VALUE self)
{
    trace_object_allocations_start(self);
    return rb_ensure(rb_yield, Qnil, trace_object_allocations_stop, self);
}

.trace_object_allocations_clear (mod_func)

Clear recorded tracing information.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 326

static VALUE
trace_object_allocations_clear(VALUE self)
{
    struct traceobj_arg *arg = get_traceobj_arg();

    /* clear tables */
    st_foreach(arg->object_table, free_values_i, 0);
    st_clear(arg->object_table);
    st_foreach(arg->str_table, free_keys_i, 0);
    st_clear(arg->str_table);

    /* do not touch TracePoints */

    return Qnil;
}

.trace_object_allocations_debug_start (mod_func)

Starts tracing object allocations for GC debugging. If you encounter the BUG "... is T_NONE" (and so on) on your application, please try this method at the beginning of your app.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 417

static VALUE
trace_object_allocations_debug_start(VALUE self)
{
    tmp_keep_remains = 1;
    if (object_allocations_reporter_registered == 0) {
        object_allocations_reporter_registered = 1;
        rb_bug_reporter_add(object_allocations_reporter, 0);
    }

    return trace_object_allocations_start(self);
}

.trace_object_allocations_start (mod_func)

Starts tracing object allocations.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 275

static VALUE
trace_object_allocations_start(VALUE self)
{
    struct traceobj_arg *arg = get_traceobj_arg();

    if (arg->running++ > 0) {
        /* do nothing */
    }
    else {
        if (arg->newobj_trace == 0) {
            arg->newobj_trace = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ, newobj_i, arg);
        }
        rb_tracepoint_enable(arg->newobj_trace);
    }

    return Qnil;
}

.trace_object_allocations_stop (mod_func)

Stop tracing object allocations.

Note that if .trace_object_allocations_start is called n-times, then tracing will stop after calling .trace_object_allocations_stop n-times.

[ GitHub ]

  
# File 'ext/objspace/object_tracing.c', line 302

static VALUE
trace_object_allocations_stop(VALUE self)
{
    struct traceobj_arg *arg = get_traceobj_arg();

    if (arg->running > 0) {
        arg->running--;
    }

    if (arg->running == 0) {
        if (arg->newobj_trace != 0) {
            rb_tracepoint_disable(arg->newobj_trace);
        }
    }

    return Qnil;
}