ObjectSpace._id2ref返回的以下两种错误之间有什么区别?
0x... is recycled object (RangeError)
0x... is not id value (RangeError)发布于 2012-11-22 20:24:35
not id value意味着从来没有具有该id的对象。
recycled object意味着曾经有一个具有该id的对象,但是它已经被垃圾回收了。
Ruby 1.9.3/Ubuntu上的演示:
x = Object.new
id = x.object_id
puts "0x%x" % id
# => 0x4aef5e8
puts ObjectSpace._id2ref id
# => #<Object:0x95debd0>
x = nil
puts ObjectSpace._id2ref id
# => #<Object:0x95debd0>
GC.start
puts ObjectSpace._id2ref id
# => 0x4aef5e8 is recycled object (RangeError)注意,Object#to_s中的数字不是object_id --根据docs的说法,它是“对象id的编码”。
https://stackoverflow.com/questions/13508536
复制相似问题