Create a gist now

Instantly share code, notes, and snippets.

Test different kind of finalizers
#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