Skip to content
class method

ObjectSpace.trace_object_allocations

() { (untyped) -> untyped } -> untyped
trace_object_allocations { block }

Starts tracing object allocations from the ObjectSpace extension module.

For example:

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.