Created
July 4, 2012 06:21
-
-
Save funny-falcon/3045699 to your computer and use it in GitHub Desktop.
Test different kind of finalizers
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
#GC.stress = true | |
STDOUT.sync = true | |
$stdout.sync = true | |
KIND = ARGV[0] || 'inner' | |
def finalizer(i) | |
proc{|id| puts "HI #{i} #{id}"} | |
end | |
def a(i) | |
b = (1..100).to_a | |
if KIND == 'inner' | |
ObjectSpace.define_finalizer(b, proc{|id| puts "HI #{i} #{id}" }) | |
elsif KIND == 'block' | |
ObjectSpace.define_finalizer(b){|id| puts "HI #{i} #{id}" } | |
else | |
ObjectSpace.define_finalizer(b, finalizer(i)) | |
end | |
b | |
end | |
def c() | |
b = a(-1) | |
puts "assigned" | |
b = nil | |
puts "deassigned" | |
i = 0 | |
while i < 100000 | |
b = a(i) | |
if i % 100 == 0 | |
puts i | |
GC.start | |
end | |
i += 1 | |
end | |
b = nil | |
puts "stop" | |
end | |
c() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment