From: John Winters Date: 2008-08-01T15:15:14+09:00 Subject: Re: gc doesn't collect? Roger Pack wrote: > Any ideas why: > > 1.times { a = 'a'*1000}; > 30.times { GC.start }; > print ObjectSpace.each_object{|o| print o} I presume you don't really want both those invocations of "print"? > prints out 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...' despite the fact that > the a's should have been collected? For the record, I've just tested this with Ruby 1.8.7 running on Debian Lenny (x86-64) and it does not print 'aaaaaaa...' I also tried this code: 1.times { a = 'a'*1000}; puts a To test the earlier assertion that "a" has not gone out of scope. This produces a run-time error because it has in fact gone out of scope so Roger seems right in expecting it to have been garbage collected. I've also tested it with and without the explicit call on GC.start. Without the call the object is still there. With just a single call (30 calls not needed) the object is gone. John -- Posted via http://www.ruby-forum.com/.