Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors from `ObjectSpace._id2ref`

What is the difference between the following two kinds of errors that ObjectSpace._id2ref returns?

0x... is recycled object (RangeError)

0x... is not id value (RangeError)
like image 509
sawa Avatar asked Sep 19 '25 12:09

sawa


1 Answers

not id value means that there never was an object with that id.

recycled object means that there once was an object with that id, but it has been garbage collected.

Demo on 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)

Note that the number in Object#to_s is not the object_id - according to the docs it is "an encoding of the object id".

like image 115
Andrew Haines Avatar answered Sep 21 '25 12:09

Andrew Haines