From: Eric Hodel Date: 2007-12-21T16:40:06+09:00 Subject: Re: First stab at a weakref test suite On Dec 20, 2007, at 21:45 PM, Daniel Berger wrote: > Hi all, > > I decided to take a stab at creating a minimal test suite for > WeakRef (based on a post by Charles Oliver Nutter for JRuby). The > only problem is that I get two unexpected failures. I'm not sure if > it's Test::Unit fighting with me or what. > > Consider the following example: > > require 'weakref' > str = 'hello' > ref = WeakRef.new(str) > > p ref 'hello' > GC.start > p ref 'hello' > str = nil > p ref # 'hello' > GC.start > p ref # error > > I follow the same pattern in the tests, but it doesn't raise the > expected error. Any ideas? Since the GC is conservative, references may exist longer than you expect because the item that should be collected is still referenced from the stack. I don't know of an easy way around this.