From: Ryan Davis Date: 2008-07-31T12:39:18+09:00 Subject: Re: gc doesn't collect? On Jul 30, 2008, at 17:40 , Eric Hodel wrote: > On Jul 30, 2008, at 17:13 PM, Roger Pack wrote: >> Any ideas why: >> >> 1.times { a = 'a'*1000}; >> 30.times { GC.start }; >> print ObjectSpace.each_object{|o| print o} >> >> prints out 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...' despite the fact >> that >> the a's should have been collected? > > Ruby's garbage collector walks the C stack looking for values that > appear to point to the ruby heap. Ruby thinks you still have a > reference to your string because of this. well... I think in this case it is because he never dereferenced a, so it is still a valid live object. {} doesn't scope variables the same way as in, say, C.