Jean-Claude Arbaut <jcarbaut / laposte.net> wrote:
(2005/10/25 08:19)

>I tried the demos in /ruby/ext/tk/sample/demos-en/widget
>and the Animation demo "A Celebration of Rube Goldberg"
>crashes with the following Tk message:
>
>  failed to allocate memory
>  failed to allocate memory
>      while executing
>  "rb_after a00000"
>      ("after" script)
>
>It can crash when launching this demo, or when running,
>or even when running for the 2nd or 3st time.
>
>I tried with Ruby 1.8.3 and it seems to work, so I suppose
>it doesn't come from my version of Tcl/Tk. In case
>it helps, I have MacOSX 10.4 with Tcl/Tk 8.4 (installed
>with the OS).
>
>Does anybody know where this error can come from ?

This error comes from this change. (this change is done because in some cases, ALLOC_N
or some other stuff causing GC can be called before interpreter is initialized)

http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/gc.c.diff?r1=1.209;r2=1.211

E:\ruby-cvs\win32>irb
"..\\ruby"
irb(main):001:0> GC.disable
=> false
irb(main):002:0> Array.new(100000)
E:/ruby-cvs/ruby/lib/irb.rb:298:in `inspect': failed to allocate memory (NoMemor
yError)
        from E:/ruby-cvs/ruby/lib/irb.rb:298:in `output_value'
        from E:/ruby-cvs/ruby/lib/irb.rb:151:in `eval_input'
        from E:/ruby-cvs/ruby/lib/irb.rb:259:in `signal_status'
        from E:/ruby-cvs/ruby/lib/irb.rb:147:in `eval_input'
        from E:/ruby-cvs/ruby/lib/irb/ruby-lex.rb:244:in `each_top_level_stateme
nt'
        from E:/ruby-cvs/ruby/lib/irb/ruby-lex.rb:230:in `each_top_level_stateme
nt'
        from E:/ruby-cvs/ruby/lib/irb/ruby-lex.rb:229:in `each_top_level_stateme
nt'
        from E:/ruby-cvs/ruby/lib/irb.rb:146:in `eval_input'
        from E:/ruby-cvs/ruby/lib/irb.rb:70:in `start'
        from E:/ruby-cvs/ruby/lib/irb.rb:69:in `start'
        from ../ruby/bin/irb:13

ruby/tk calls rb_gc_disable in many places, so probably this error occurs in that section.

This adhok patch seems to prevent this error, but I don't think this patch is good enough.
(I don't know GC mechanizm. Just tried and run fine.)

Index: gc.c
===================================================================
RCS file: /src/ruby/gc.c,v
retrieving revision 1.214
diff -u -w -b -p -r1.214 gc.c
--- gc.c	18 Oct 2005 17:35:18 -0000	1.214
+++ gc.c	25 Oct 2005 02:35:28 -0000
@@ -1280,6 +1280,7 @@ garbage_collect(void)
     if (dont_gc || during_gc) {
 	if (!freelist) {
 	    add_heap();
+	    return Qtrue;
 	}
 	return Qfalse;
     }