Skip to content

Instantly share code, notes, and snippets.

@funny-falcon
Created July 4, 2012 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funny-falcon/3045699 to your computer and use it in GitHub Desktop.
Save funny-falcon/3045699 to your computer and use it in GitHub Desktop.
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