From: Brent Roman Date: 2008-11-13T10:46:26+09:00 Subject: [ruby-core:19903] Re: [Bug #744] memory leak in callcc? Roger, I've run into a number of issues related to Continuations and MRI's garbage collector, so I thought I'd have a look at this one. I investigated the equivalent (non-generator) example described at: http://rubyforge.org/tracker/?func=detail&atid=1698&aid=7896&group_id=426 This: loop {@x = callcc {|c| c}} quickly consumes all of memory. One of my x86 Linux machines crashed after a couple minutes of running this loop with a Segmentation Fault. My guess here is that the stack, which during GC is unchecked, got too deep. What I saw is that the stack during garbage collection became rediculously deep. (>15000 frames deep in the GC) Here's a bit of the backtrace: #11768 0x0806401a in mark_locations_array (x=0xa887004, n=1228) at gc.c:437 #11769 0x0805dceb in thread_mark (th=0xa8860f8) at eval.c:7403 #11770 0x0806438e in rb_gc_mark (ptr=59) at gc.c:881 #11771 0x0806401a in mark_locations_array (x=0xa88924c, n=1228) at gc.c:437 #11772 0x0805dceb in thread_mark (th=0xa888340) at eval.c:7403 #11773 0x0806438e in rb_gc_mark (ptr=59) at gc.c:881 #... This looks like rb_gc_mark() got passed a bogus VALUE pointer. I cannot even unwind the stack to the point where this happened without gdb itself segfaulting. Interestinly, the very same Ruby interpreter running on an ARM9 under Linux handles this case without leaking memory or segfaulting. So, in answer to your original question: I don't think this behavior is intentional. And, I plan to spend a bit more time looking into it. Any hints would be appreciated... - brent Roger Pack-5 wrote: > > Bug #744: memory leak in callcc? > http://redmine.ruby-lang.org/issues/show/744 > > Author: Roger Pack > Status: Open, Priority: Normal > > from > http://rubyforge.org/tracker/?func=detail&atid=1698&aid=7896&group_id=426 > this code > require 'generator' > loop { g = Generator.new {|x| (1..3).each {|i| x.yield i}} } > > seems to leak for me--I'm not sure if this is expected or not. > > Thanks. > > > ---------------------------------------- > http://redmine.ruby-lang.org > > > -- View this message in context: http://www.nabble.com/-ruby-core%3A19846---Bug--744--memory-leak-in-callcc--tp20447794p20472962.html Sent from the ruby-core mailing list archive at Nabble.com.