From: ahoward Date: 2002-10-31T04:38:23+09:00 Subject: define_finalizer does NOT work rubyists- i searched the wiki and comp.lang.ruby and found several examples of using finalizers. strangely, though they work for some people, not all work for me : #!/usr/bin/env ruby class Test def Test.finalizer Proc.new{ puts "finalizing" } end def initialize ObjectSpace.define_finalizer(self, Test.finalizer) end end t = Test.new class A def initialize ObjectSpace.define_finalizer(self, proc{|id| puts "final #{id}"}) end end a = A.new outputs only "finalizing" thus the second technique does not work... here's my setup /tmp > uname -a Linux 2.4.2-2 #1 SMP Fri Nov 23 20:51:15 GMT 2001 i686 unknown /tmp > ruby -v ruby 1.6.6 (2001-12-26) [i686-linux] i found quite a few references that claim the finalizing proc may not contain references to the object in question, since it would therefore, never be candidate for gc... my experiements show this to be true, but 'the book' seems to think otherwise... what's the deal? from the book: define_finalizer ObjectSpace.define_finalizer( anObject, aProc=proc() ) Adds aProc as a finalizer, to be called when anObject is about to be destroyed. note the 'about' part. is this correct? thanks for any insight. -ara -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================