ruby 2.0 undefined method ObjectSpace.trace_object_allocations

1.4k views Asked by At

tried this on ruby 2.0.0 / 247 or head:

require 'objspace'
ObjectSpace.trace_object_allocations -> undefined method `trace_object_allocations' 
for ObjectSpace:Module

Docs say it should work http://www.ruby-doc.org/stdlib-2.0/libdoc/objspace/rdoc/ObjectSpace.html any idea what I'm missing ?

3

There are 3 answers

0
Daniel Garmoshka On

For higher ruby versions you still may get errors like:

undefined method `memsize_of' for ObjectSpace:Module

To solve this issue -> You need to require 'objspace'. According to https://ruby-doc.org/stdlib-2.3.1/libdoc/objspace/rdoc/ObjectSpace.html#method-c-memsize_of

0
grosser On

Only available when installing ruby-head aka ruby 2.1

0
Daniel Brady On

From the output of puts ObjectSpace.methods.sort after requiring objspace, it looks like that method doesn't exist.

irb(main):005:0> puts ObjectSpace.methods.sort
...
reachable_objects_from
remove_class_variable
remove_instance_variable
respond_to?
send
singleton_class
singleton_methods
 taint
tainted?
tap
to_enum
to_s
trust
undefine_finalizer
untaint
untrust
untrusted?
=> nil
irb(main):009:0> ObjectSpace.methods.include? :trace_object_allocations
=> false

You can see that it contains the ::reachable_objects_from method, which is mentioned in the docs, but not the one you're looking for, unfortunately.