From: Samuel Tesla Date: 2003-12-06T12:52:06+09:00 Subject: Re: WeakRef and Object#hash "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. Somehow, I don't think this is intended behavior. I don't know enough about Ruby internals to say for sure (although I'm reading the code right now, so I will soon enough). Matz? Cheerio, Samuel (Trying to figure this out, sure is fun)