From: Dave Thomas Date: 2008-04-11T07:33:26+09:00 Subject: Re: How can I demonstrate that weakref works in 1.9? On Apr 10, 2008, at 5:21 PM, David A. Black wrote: >> So, assuming Weakref works in 1.9, is there a clever way of >> demonstrating it? > > I wanted to try this out and investigate but I can't seem to get the > exception out of 1.8: > > $ ruby -v weakref.rb ruby 1.8.6 (2007-09-24 patchlevel 111) > [universal-darwin9.0] > Initial object is fol de rol > Weak reference is fol de rol > But then it is fol de rol Yeah, I'm seeing that too. I believe the exception was reliable on 1.8.4, so GC may have changed in 1.8. I tried putting the variable in a function: require 'weakref' def gen_reference ref = "fol de rol" puts "Initial object is #{ref}" WeakRef.new(ref) end ref = gen_reference puts "Weak reference is #{ref}" ObjectSpace.garbage_collect puts "But then it is #{ref}" Still no IllegalReference exception on either 1.8.6 or 1.9. So... any ideas? I don;t want to publish code without a working example. Thanks Dave