From: Brent Roman Date: 2008-11-17T12:54:56+09:00 Subject: [ruby-core:19968] Re: [Bug #744] memory leak in callcc? Roger, Well, I just summarized the result of this Saturday's hackfest at: http://rubyforge.org/tracker/?func=detail&atid=1698&aid=7896&group_id=426 The main problem seems to be that 'C'/C++ compilers do not initialize automatic variables, so one is bound to have old, unused, but valid pointers left on the stack from previous at any point in time. By the way, even this will fix the example leak: loop {@x = callcc {|c| c}; 2*6+4} Pretty silly, but it works for me. And, the fact it works proves that the issue is unused references left on the stack. The behavior is a fundamental design weakness of conservative GC. We notice it most when managing large and/or highly connected objects like threads, continuations and large arrays. One could hack the gcc to force it to initialize automatic variables to zero even though this violates the 'C' langauage spec. But I can't help feeling that there must be a better way. In my on again off again quest to put Ruby on a diet, I'll probably hack at this a bit more over to coming weeks, initially on my patched v1.68 interpreter. Thanks for the redmine link. Found this hanging off it. Looks better than the "reachability" patches to GC: http://softwareverify.com/ruby/customBuild/memtrack/index.html Here are some interesting posts about this problem from outside the Ruby world. The first is especially relevant: http://gcc.gnu.org/ml/java/2005-05/msg00265.html http://www.red-bean.com/guile/guile/new/msg01070.html http://www.digitalmars.com/rtl/gcdescr.html - brent Roger Pack-5 wrote: > > Issue #744 has been updated by Roger Pack. > > >> If we knew what wrote these, we might be able to explicitly clear them >> once >> they go out of scope. This should result in better significantly GC >> performance all around. > > Yeah I've wondered that too. Maybe we can have a hackfest for it some > saturday :) > http://redmine.ruby-lang.org/issues/show/649 > is related [and somewhat frustrating to be honest]. My thought is that > maybe there's a way to "clear the stack" of data that isn't currently > "useful" and thus clear it of old references [I realize this may be hard]. > > Thoughts? > -=R > ---------------------------------------- > http://redmine.ruby-lang.org/issues/show/744 > > ---------------------------------------- > http://redmine.ruby-lang.org > > > -- View this message in context: http://www.nabble.com/-ruby-core%3A19846---Bug--744--memory-leak-in-callcc--tp20447794p20533504.html Sent from the ruby-core mailing list archive at Nabble.com.