Finalizers be called at interrupt?

Hello all.

I noticed that in MRI, this code:

def finalized_puts bad, benign
ObjectSpace.define_finalizer(bad) { puts benign.to_s }
end

n = 0
loop {
a = [3]
finalized_puts a, n
n += 1
print ‘.’
}

If I hit ‘ctrl-c’ to interrupt it, in MRI the finalizers are run, but no
in Jruby. Is this expected? Will file a bug report eventually if no
response.
Cheers!
-roger-

References won’t be collected immediately upon interrupt (and
therefore the finalizers won’t be run) - it’ll happen when the GC
needs to reclaim memory.

But, won’t your finalized_puts bind the ‘bad’ param in the block, and
stop it from being collected? (i.e. the block will always have a ref
to the bad instance, and won’t allow it to be collected).

if you change it to something like this, it might work:

def finalized_puts bad, benign
ObjectSpace.define_finalizer(bad, create_finalizer(benign))
end

def create_finalizer(benign)
Proc.new { |bad| puts benign.to_s }
end