来自`ObjectSpace._id2ref`的错误

ObjectSpace._id2ref返回的以下两种错误有什么区别?

 0x... is recycled object (RangeError) 0x... is not id value (RangeError) 

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 # => # x = nil puts ObjectSpace._id2ref id # => # GC.start puts ObjectSpace._id2ref id # => 0x4aef5e8 is recycled object (RangeError) 

请注意, Object#to_s中的数字不是 object_id – 根据文档,它是“对象id的编码”。