Skip to content

Instantly share code, notes, and snippets.

@jpr5
Created Dec 2, 2009
Embed
What would you like to do?
jpr5@finesse(tmp)$ ruby foo.rb
2148181980 born
2148181820 born
2148181660 born
2148181500 born
2148181340 born
nuke class constant
done
calling GC.start
done
exiting
2148181340 dying
2148181500 dying
2148181660 dying
2148181820 dying
2148181980 dying
jpr5@finesse(tmp)$
#!/usr/bin/ruby
class Foo
@foo = "bar"
end
finalizer = proc { |id| puts "#{id} dying" }
objs = 1.upto(5).inject([]) do |l, n|
obj = Foo.new
puts "#{obj.object_id} born"
ObjectSpace.define_finalizer(obj, finalizer)
l << obj
end
puts "nuke class constant"
Object.class_eval do
remove_const :Foo
end
puts "done"
sleep 1
puts "calling GC.start"
GC.start
puts "done"
at_exit {
puts "exiting"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment