Finding Object by Its Object ID
Ruby comes with a wonderful module called ObjectSpace that allows me to find a lost object as long as I have its object_id and granted it hasn’t been GCed. Here’s a bit of code to illustrate this.
>> a = "hello"
=> "hello"
>> id = a.object_id
=> 3116970
>> a = nil # oh no!
=> nil
>> b = ObjectSpace._id2ref(id)
=> "hello"
>> b
=> "hello" # the original "a" has been restored to "b"
Armed with this, I can now see how long objects live after a request has been served by the Rails.