I am having problems with weak references. The program below exhibits
the problem:

100_000.times{|n|
  o=Object.new;
  i=o.__id__;
  o2=ObjectSpace._id2ref(i);
  o.equal? o2 or raise "o=#{o}, i=#{"%x"%i}, o2=#{o2.inspect}, n=#{n}"
}

The exception should never be raised. On my OS X 10.3.9 system (and at
least 1 other) it does get eventually raised after a few hundred
iterations using ruby 1.8 and 1.9. With the (apple-supplied) ruby 1.6,
it does not happen. Tests on several Windows and Linux systems have
never observed a problem, using ruby 1.8 and 1.9. I don't know if it's
a problem on OS X 10.4; I don't have access to any 10.4 systems.

The problem seems to be in the call to __id__. Usually, it works
correctly, but every once in a while it returns the id of some random
symbol. Does anyone know why this is happening?