From: Guillaume Cottenceau Date: 2005-04-13T19:58:58+09:00 Subject: Re: ability to run finalizers at a given point of a program? > > 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. > > Incorrect. The first argument is irrelevant. > ObjectSpace::define_finalizer is written this way probably to make > things ugly. You have to pass in the object you wish to attach a > finalizer to, and that's what the first arg is for. I wasn't pretending it would retain a reference, I was just comparing both versions and underlined that both had that. > In your version, foo is in-scope when the finalizer proc is created, so > the proc captures foo *even though it is not explicitly used in the > proc*. That's right! Just because you don't reference foo inside a > closure doesn't mean it magically disappears for you. Thanks, I was wrong on that very matter. I thought a closure only captured the necessary environment, not the whole of it (what is necessary being decided at closure creation time). And I can't duplicate such ruby's behaviour in perl :/ Perl in my example doesn't capture the whole environment when creating the closure: http://www.zarb.org/~gc/t/prog/closures_wholecapture/ -- Guillaume Cottenceau - http://zarb.org/~gc/