From: Florian Frank Date: 2007-08-03T09:27:11+09:00 Subject: Re: finalizer not getting called Joshua Chia wrote: > The finalizer is not getting called in this code -- it just prints > 'exiting'. What's wrong? I'm running it on v1.8.6 on Windows Vista. > > class A > def initialize > ObjectSpace.define_finalizer(self, proc{|id| puts "finalizing > #{id}"}) > end > end > a = A.new > a = nil > GC.start > sleep(5) > puts 'exiting' If the answer is finalizer in Ruby, then it's very likely, that you're working on the wrong problem. They are quite difficult to get right (=not referencing the value to be finalized anywhere). You could use a class variable for example: class A @@foo = proc{|id| puts "finalizing #{id}"} def initialize ObjectSpace.define_finalizer(self, @@foo) end end Another possibility is to use a binding, that doesn't -- Florian Frank