I was experimenting with weakrefs and I could not get my string
GCed. I found out it was because I assigned it before requiring weakref.
Like this:
···
ref = "fol de rol"
require “weakref”
puts "Initial object is #{ref}"
ref = WeakRef.new(ref)
puts "Weak reference is #{ref}"
ObjectSpace.garbage_collect
puts “But then it is #{ref}”
It produces no errors and prints all three lines.
ruby 1.6.7 (2002-03-01) [powerpc-darwin6.6]
Swapping the first two lines (like they are in the pickaxe example) makes
it work as expected.
Michal Suchanek
hramrach@centrum.cz