# ObjectSpace.\_id2ref is giving different type output on Ruby 1.9.3p392 and Ruby 2.0.0p0?

**URL:** <https://rubytalk.org/t/objectspace-id2ref-is-giving-different-type-output-on-ruby-1-9-3p392-and-ruby-2-0-0p0/67522>\
**Category:** ruby-talk\
**Created:** [17 March 2013 08:41 UTC](https://rubytalk.org/t/objectspace-id2ref-is-giving-different-type-output-on-ruby-1-9-3p392-and-ruby-2-0-0p0/67522 "2013-03-17T08:41:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [17 March 2013 08:41 UTC](https://rubytalk.org/t/objectspace-id2ref-is-giving-different-type-output-on-ruby-1-9-3p392-and-ruby-2-0-0p0/67522/1 "2013-03-17T08:41:53Z")

</div>

Couldn't understand - Why does `ObjectSpace._id2ref` giving different  
type of output on `Ruby 1.9.3p392` and `Ruby 2.0p0` ?

\*\*\*Ruby 1.9.3p392\*\*\*

&nbsp;&nbsp;&nbsp;&nbsp;C:\\>ruby -v  
&nbsp;&nbsp;&nbsp;&nbsp;ruby 1.9.3p392 (2013-02-22) [i386-mingw32]  
&nbsp;&nbsp;&nbsp;&nbsp;C:\\>irb --simple-prompt  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> class Foo ; end  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> nil  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> Foo.object\_id  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> 17569464  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> ObjectSpace.\_id2ref(17569464)  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> Foo  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> Foo.new.singleton\_class  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> #\<Class:#\<Foo:0x2041830\>\>  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> Foo.new.singleton\_class.object\_id  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> 17075124  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> ObjectSpace.\_id2ref(17075124)  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> "\x00"

\*\*\*Ruby 2.0.0p0\*\*\*

&nbsp;&nbsp;&nbsp;&nbsp;C:\\>ruby -v  
&nbsp;&nbsp;&nbsp;&nbsp;ruby 2.0.0p0 (2013-02-24) [i386-mingw32]  
&nbsp;&nbsp;&nbsp;&nbsp;C:\\>irb --simple-prompt  
&nbsp;&nbsp;&nbsp;&nbsp;DL is deprecated, please use Fiddle  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> class Foo ; end  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> nil  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> Foo.object\_id  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> 17197176  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> ObjectSpace.\_id2ref(17197176)  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> Foo  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> Foo.new.singleton\_class.object\_id  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> 19181436  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> ObjectSpace.\_id2ref(19181436)  
&nbsp;&nbsp;&nbsp;&nbsp;#RangeError: 0x124af7c is recycled object  
&nbsp;&nbsp;&nbsp;&nbsp;# from (irb):5:in `\_id2ref'  
&nbsp;&nbsp;&nbsp;&nbsp;# from (irb):5  
&nbsp;&nbsp;&nbsp;&nbsp;# from C:/Ruby200/bin/irb:12:in `\<main\>'  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> Foo.new.singleton\_class.object\_id  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> 17454324  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> ObjectSpace.\_id2ref(17454324)  
&nbsp;&nbsp;&nbsp;&nbsp;#RangeError: 0x10a54f4 is not id value  
&nbsp;&nbsp;&nbsp;&nbsp;# from (irb):7:in `\_id2ref'  
&nbsp;&nbsp;&nbsp;&nbsp;# from (irb):7  
&nbsp;&nbsp;&nbsp;&nbsp;# from C:/Ruby200/bin/irb:12:in `\<main\>'  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> Foo.new.singleton\_class.object\_id  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> 17139816  
&nbsp;&nbsp;&nbsp;&nbsp;\>\> ObjectSpace.\_id2ref(17139816)  
&nbsp;&nbsp;&nbsp;&nbsp;#=\> "c"

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [17 March 2013 08:47 UTC](https://rubytalk.org/t/objectspace-id2ref-is-giving-different-type-output-on-ruby-1-9-3p392-and-ruby-2-0-0p0/67522/2 "2013-03-17T08:47:47Z")

</div>

already fixed in ruby-trunk

and before you ask, yeah the object\_id of nil is changed in ruby-trunk  
too

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
