From: Robert Klemme Date: 2003-12-08T19:32:06+09:00 Subject: Re: WeakRef and Object#hash "Samuel Tesla" schrieb im Newsbeitrag news:878ylqa9py.fsf@hiro.int.procacious.com... > "Robert Klemme" writes: > > I guess it's by design. But you can fix this easily by sub classing > > WeakRef > > Indeed. One would think that would work, however. Look at the > following two code samples. > > > ## > # Sample 1 - test1.rb > ## > require 'weakref' > > a = WeakRef.new(Object.new) # We'll just never make a strong ref > GC.start > puts a > > # Output: > # test1.rb:8:in `puts': Illegal Reference - probably recycled > # (WeakRef::RefError) from test1.rb:8 > > ## END test1.rb > > ## > # Sample 2 - test2.rb > ## > require 'weakref' > > class WeakRef; end > > a = WeakRef.new(Object.new) # We'll just never make a strong ref > GC.start > puts a > > # Output: > # > > ## END test2.rb > > As you can see, I'm not even adding methods, and it causes the weak > reference to not be recycled by the garbage collector. I had similar experiences about references not beeing cleared. Maybe someone with more insight (Matz?) should comment on this. Maybe only an instance's type is checked against WeakRef and not if it's a subtype of that. Regards robert