Skip to content

Instantly share code, notes, and snippets.

@dblack
Created June 29, 2012 12:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dblack/3017739 to your computer and use it in GitHub Desktop.
Save dblack/3017739 to your computer and use it in GitHub Desktop.
weakref behavior
This is from the end of weakref.rb:
if __FILE__ == $0
# require 'thread'
foo = Object.new
p foo.to_s # original's class
foo = WeakRef.new(foo)
p foo.to_s # should be same class
ObjectSpace.garbage_collect
ObjectSpace.garbage_collect
p foo.to_s # should raise exception (recycled)
end
And this is the output from running it (no exception raised):
"#<Object:0x000001010b3ea0>"
"#<Object:0x000001010b3ea0>"
"#<Object:0x000001010b3ea0>"
Any thoughts on why? I haven't yet delved deeply into the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment