# \_id2ref bug?

**URL:** <https://rubytalk.org/t/id2ref-bug/7415>\
**Category:** ruby-talk\
**Created:** [14 August 2003 16:45 UTC](https://rubytalk.org/t/id2ref-bug/7415 "2003-08-14T16:45:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Pavlik2](https://avatars.discourse-cdn.com/v4/letter/r/aeb1de/32.png) [@Ryan\_Pavlik2](https://rubytalk.org/u/Ryan_Pavlik2)\
**Post date:** [14 August 2003 16:45 UTC](https://rubytalk.org/t/id2ref-bug/7415/1 "2003-08-14T16:45:02Z")

</div>

While debugging some caching code, I’ve come across a segfault related  
to ObjectSpace::\_id2ref. Apparently it’s returning illegal objects:

Remote Exception: NotImplementedError:  
/usr/local/encap/mephle-0.8.0/share/mephle/Driver/Storage\_cache.rb:49:in  
`cache': method`\_oid’ called on terminated object (0x4043a568)

The code up to this point:

…  
o = ObjectSpace::\_id2ref(id)  
cache(o)  
rescue RangeError …  
…

def cache(object)  
oid = object.\_oid # line 49  
…  
end

It seems that somehow, it’s returning a bad object, or the object is  
getting collected after the fact, or something. I’m checking for  
RangeError, and this isn’t getting raised. I tried GC.start  
and Thread.critical=true, around this block. Same deal.

Sometimes it outright segfaults.

So far, I haven’t been able to reproduce this with a tiny script.  
However, I have been able to confirm that it is getting collected, by  
checking the **id** ’s via a finalizer. So \_id2ref is somehow returning  
a collected object.

Not using \_id2ref isn’t really an option; it’s critical to maintaining  
integrity, so I can’t really get around using it.

> **···**
>
> –  
> Ryan Pavlik [rpav@users.sf.net](mailto:rpav@users.sf.net)
> 
> “I distinctly remember dancing on your grave.” - 8BT
