6

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 ?

grosser
  • 14,707
  • 7
  • 57
  • 61
  • Probably included in not yet released version/patchlevel. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?view=markup&pathrev=40957 – Torimus Jul 26 '13 at 22:13

3 Answers3

4

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

Daniel Garmoshka
  • 5,849
  • 39
  • 40
2

Only available when installing ruby-head aka ruby 2.1

grosser
  • 14,707
  • 7
  • 57
  • 61
0

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.

Daniel Brady
  • 934
  • 3
  • 11
  • 27