Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Object finalizer broken in ruby 1.9.3
$ ruby -v
ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux]
$ # Ruby 1.9.2 fails to run finalizer until program exit
$ ruby test_finalizer.rb outter
assigned
deassigned
stop
HI 9472020
$ ruby test_finalizer.rb inner
assigned
deassigned
stop
HI 8185780
$ ruby test_finalizer.rb block
assigned
deassigned
stop
HI 11071500
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ # Ruby 1.9.3 fails to run finalizer until program exit
$ ruby test_finalizer.rb outter
assigned
deassigned
stop
HI 11754960
$ ruby test_finalizer.rb inner
assigned
deassigned
stop
HI 10755540
$ ruby test_finalizer.rb block
assigned
deassigned
stop
HI 10309080
$ ruby -v
ruby 1.8.7 (2012-02-08 MBARI 8/0x6770 on patchlevel 358) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2012.02
$ # REE do finalization right
$ ruby test_finalizer.rb outter
assigned
deassigned
HI 18454540
stop
$ # But still suffers from Proc binding reference
$ ruby test_finalizer.rb inner
assigned
deassigned
stop
HI 8632340
$ ruby test_finalizer.rb block
assigned
deassigned
stop
HI 19691460
$ ./ruby -I. -I.. -I../lib -Iext -I.ext/x86_64-linux -v
ruby 2.0.0dev (2012-06-28 trunk 36243) [x86_64-linux]
$ ./ruby -I. -I.. -I../lib -Iext -I.ext/x86_64-linux ../../test_finalizer.rb outter
assigned
deassigned
stop
HI 70101891948480
$ ./ruby -I. -I.. -I../lib -Iext -I.ext/x86_64-linux ../../test_finalizer.rb inner
assigned
deassigned
stop
HI 70286489477060
$ ./ruby -I. -I.. -I../lib -Iext -I.ext/x86_64-linux ../../test_finalizer.rb block
assigned
deassigned
stop
HI 70110030782400
GC.stress = true
KIND = ARGV[0] || 'inner'
def finalizer
proc{|i| puts "HI #{i}"}
end
def a()
b = (1..100).to_a
if KIND == 'inner'
ObjectSpace.define_finalizer(b, proc{|i| puts "HI #{i}" })
elsif KIND == 'block'
ObjectSpace.define_finalizer(b){|i| puts "HI #{i}" }
else
ObjectSpace.define_finalizer(b, finalizer)
end
b
end
def c()
b = a()
puts "assigned"
b = nil
puts "deassigned"
i = 0
while i < 100
b = [];
j = i
while j >= 0
b << [j]
j -= 1
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
You can’t perform that action at this time.