6

在 ruby​​ 2.0.0 / 247 或 head 上试过这个:

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

文档说它应该可以工作http://www.ruby-doc.org/stdlib-2.0/libdoc/objspace/rdoc/ObjectSpace.html知道我缺少什么吗?

4

3 回答 3

4

对于更高的 ruby​​ 版本,您仍然可能会收到如下错误:

undefined method `memsize_of' for ObjectSpace:Module

要解决此问题 -> 您需要require 'objspace'. 根据https://ruby-doc.org/stdlib-2.3.1/libdoc/objspace/rdoc/ObjectSpace.html#method-c-memsize_of

于 2018-06-06T15:16:53.053 回答
2

仅在安装 ruby​​-head aka ruby​​ 2.1 时可用

于 2013-07-28T00:38:28.207 回答
0

puts ObjectSpace.methods.sortafter requires的输出来看objspace,该方法似乎不存在。

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

您可以看到它包含::reachable_objects_from文档中提到的方法,但不幸的是,它不是您要查找的方法。

于 2013-07-27T01:31:27.523 回答