From: Rick DeNatale Date: 2008-01-11T08:41:38+09:00 Subject: Re: why does this code leak? On 1/10/08, MenTaLguY wrote: > On Fri, 11 Jan 2008 07:09:04 +0900, "Rick DeNatale" wrote: > > Now since the VM doesn't look inside the block when creating a proc, > > it has to assume that the binding of he context in which the block was > > created has to be captured. > > Also, even if the VM did look inside the block to see which variables were > captured, it has to keep all of them around anyway because they have to > remain accessible because the binding is exposed via Proc#binding. Good observation! >$ qri Proc#binding ----------------------------------------------------------- Proc#binding prc.binding => binding ------------------------------------------------------------------------ Returns the binding associated with prc. Note that Kernel#eval accepts either a Proc or a Binding object as its second parameter. def fred(param) proc {} end b = fred(99) eval("param", b.binding) #=> 99 eval("param", b) #=> 99 Any optimization of procs by making them less than a full closure even those representing an empty block would break this 'specification'. On the other hand Ruby 1.9 made changes to much less obscure specifications! -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/