On May 19, 2006, at 11:24 AM, Madan Manoharan wrote: > On 5/19/06, nobu / ruby-lang.org <nobu / ruby-lang.org> wrote: >> Hi, >> >> At Fri, 19 May 2006 22:58:28 +0900, >> Madan Manoharan wrote in [ruby-talk:193553]: >> > def getATest() >> > procObj = Proc.new do |id| >> > @store.delete(id) >> > end >> > >> > t = Test.new() >> > @store.push(t.__id__) >> > >> > ObjectSpace.define_finalizer(t, procObj) >> > return t.__id__ >> > end >> >> Note that procObj also refers t, so this object will never get >> collected. >> >> procObj = @store.method(:delete).to_proc >> >> is an alternative. > > The procObj does not refer to object 't'. Even the you don't refer to t by name, procObj's environment knows about t. > Please correct me if I am wrong, or if I am missing the obvious (like > the reference to object 't' in procObj, which I cant see). You can't see them, but they are there. It is a feature of Ruby. $ cat x.rb def x p = proc { eval('p t') } t = 5 return p end x.call $ ruby x.rb 5 -- Eric Hodel - drbrain / segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com