From: Robert Dober Date: 2008-01-11T07:56:17+09:00 Subject: Re: why does this code leak? On Jan 10, 2008 11:09 PM, Rick DeNatale wrote: Thanks for your time Rick. I have just written lots of testcode and there is no need to post it, it is clear self is captured in the closure. ( Probably very useful too ). This happens for 1.9 too, so why did we get the following class Foo def initialize creation_time = Time.now ObjectSpace.define_finalizer self, lambda{ puts "An Object has died (#{creation_time}-#(Time.now}) R.I.P." end end I guess the finalizer is not used and thus the lambda thrown away: 682/183 > cat leak.rb && ruby1.9 leak.rb # vim: sw=2 ts=2 ft=ruby expandtab tw=0 nu syn: # Foo = Class::new{ def initialize ObjectSpace.define_finalizer self, lambda {p :finalized} end } (42/7).times { Foo.new GC.start p "Foo" => ObjectSpace.each_object(Foo){} } {"Foo"=>1} {"Foo"=>1} {"Foo"=>1} {"Foo"=>1} {"Foo"=>1} {"Foo"=>1} Bingo!!! Robert --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein