From: Guillaume Cottenceau Date: 2005-04-13T16:28:27+09:00 Subject: Re: ability to run finalizers at a given point of a program? > So, I am getting the same result ts was getting. Now that is strange.. :/ > > What difference do you pretend your program is making with mine? > > The difference is in this: > > (your version): > def scopeme > foo = Foo.new > ObjectSpace.define_finalizer(foo, proc { puts "*** pseudo-destructor" }) > end > > That block captures foo as well. As a result, that instance will never > be unreferenced, and thus never going to be GC'ed until the program > ends. > > OTOH, ts' version: > class Foo > def self.final > proc { puts "*** pseudo-destructor" } > end > end > > def scopeme > foo = Foo.new > ObjectSpace.define_finalizer(foo, Foo.final) > end > > Notice that the finalizer block does not capture the Foo instance. Wait.. both calls to define_finalizer have a reference to foo as the first argument, and both have a closure as second argument which doesn't have a reference to foo. I fear I just fell into a parallel universe.. -- Guillaume Cottenceau - http://zarb.org/~gc/