From: Sylvain Joyeux Date: 2008-09-22T22:42:37+09:00 Subject: Re: for or each? On Mon, Sep 22, 2008 at 07:52:47PM +0900, Brian Candler wrote: > Sylvain Joyeux wrote: > > Nope. each { } needs one new scope for each iteration while "for ... in" > > explicitely uses the parent scope... In the end, you create with #each > > as many objects as there are in your collection > > P.S. Here's a simple experiment, and I can't see any of these > dark-matter objects that you talk about. > > def countobj > count = 0 > ObjectSpace.each_object(Object) { count += 1 } > count > end > > def foo > :dummy > end > > puts "#{countobj} objects" > GC.disable > (1..1_000_000).each { foo } > puts "#{countobj} objects" Thanks but nope... each_object *specifically* filters out objects that are internal to the interpreter, therefore you don't see those here. For that, you actually need a better object-counting setup. See Ruby patches for one that I submitted. I hope that the "new Ruby GC profiler" that have been included in 1.9 will provide the same amount of information. Sylvain