Created
December 2, 2009 07:01
-
-
Save jpr5/247008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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