From: Roman Shterenzon Date: 2009-10-21T21:44:19+09:00 Subject: [ruby-core:26211] Ruby 1.9.1 embedding and GC Good day, I'm trying to embed a Ruby 1.9.1 interpreter, and I'd like to disable to GC, and only run it manually (say, every 1000 requests). The problem is, that somehow it's not disabled, and after an attempt to allocate memory the interpreter exits. I tried to understand the code, but I'm a bit lost. What I'm doing wrong here? The ruby version is: ruby 1.9.1p281 (2009-08-09 revision 24476) [i386-darwin10.0.0] My code: ----- RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); ruby_script(service_file); rb_define_module("Gem"); rb_gc_disable(); Init_prelude(); int error; rb_protect((VALUE (*)(VALUE))rb_require, (VALUE)service_file, &error); ----- The gdb backtrace (line 193 in ruby_handler.c is Array allocation): (gdb) bt #0 0x00007fff84fb5183 in exit () #1 0x0000000100233b0b in garbage_collect_with_gvl (objspace=0x10036d9c0) at gc.c:602 #2 0x0000000100233b71 in vm_xmalloc (objspace=0x10036d9c0, size=80) at gc.c:623 #3 0x0000000100204f3a in ary_new (klass=, len=10) at array.c:301 #4 0x000000010006d03b in ruby_init_request_data (req=0x1028ff800) at ruby_handler.c:193 ... (gdb) up #1 0x0000000100233b0b in garbage_collect_with_gvl (objspace=0x10036d9c0) at gc.c:602 602 exit(EXIT_FAILURE); (gdb) list 597 return (int)rb_thread_call_with_gvl(gc_with_gvl, (void *)objspace); 598} 599else { 600 /* no ruby thread */ 601 fprintf(stderr, "[FATAL] failed to allocate memory\n"); 602 exit(EXIT_FAILURE); 603} 604 } 605} 606 (gdb) up #2 0x0000000100233b71 in vm_xmalloc (objspace=0x10036d9c0, size=80) at gc.c:623 623garbage_collect_with_gvl(objspace); (gdb) list 618 size += sizeof(size_t); 619#endif 620 621 if ((ruby_gc_stress && !ruby_disable_gc_stress) || 622(malloc_increase+size) > malloc_limit) { 623garbage_collect_with_gvl(objspace); 624 } 625 mem = malloc(size); 626 if (!mem) { 627if (garbage_collect_with_gvl(objspace)) { (gdb) Another question, which might be related, is that if I don't disable GC, then I see this error: [BUG] object allocation during garbage collection phase And I assumed, that if I control the allocation and GC, then I can avoid triggering this bug, but perhaps there's a better workaround or solution. Thank you very much in advance, --Roman