Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Test different kind of finalizers

View test_finalizer.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#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
Something went wrong with that request. Please try again.