From: Rick DeNatale Date: 2008-01-11T06:35:38+09:00 Subject: Re: why does this code leak? On 1/10/08, Robert Dober wrote: > I honestly fail to see why the closure shall take a reference to the > object . I am with Ara here, no need to keep a reference to the object > and this is not only MHO but also that one of Ruby1.9;), if not a bug > at least it is odd behavior. Because the code which creates the proc doesn't do any analysis of what's inside the block. It's like the story about the guy who checked out of hotel, and protested the mini-bar charge on his bill, saying, "I didn't use anything from the mini-bar." The Hotel manager said, "I'm sorry sir, it's Hotel policy, the mini-bar was available for your use, and we have to charge a fee to maintain it." The man hesitated a second and quickly wrote out a bill for $100 and presented it to the Hotel Manager, who asked "What's this for?" The man said "For sleeping with my wife." The Hotel manager said, "I didn't sleep with your wife!" To which the man said, "But she was available for your use, and she's much more expensive to maintain than that mini-bar." Seriously, it might be possible for the Ruby parser to mark the AST or byte-codes representing a block to indicate whether or not it needed to be a closure or not, and perhaps even to limit what actually got bound, but as far as I know it doesn't. I'm also of the opinion that expecting objects to be reclaimed as rapidly as 'logically' possible might not be the best trade-off in designing a GC anyway. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/