From: matz@... (Yukihiro Matsumoto) Date: 2003-01-23T12:16:34+09:00 Subject: Re: Ruby, C, and garbage collection Hi, In message "Ruby, C, and garbage collection" on 03/01/23, Tomasz Wegrzanowski writes: | VALUE a, b, c; | | a = rb_some_function_1(); | b = rb_some_function_2(); | c = rb_do_something(a,b); | |In this code, if Ruby decides to do GC during rb_some_function_2, |`a' will be destroyed, and it will segfault at rb_do_something. I don't think so. Ruby uses conservative GC, which scans C stack region to protect Ruby object reference, so that an object referred from the variable a is not destroyed. But in some cases, local variables may vanish before function terminates, for example: VALUE a; char *p a = function_returns_string(); p = RSTRING(a)->ptr; ... process goes on referring p, but no a ... in such cases, an object referred from a might be reclaimed. For a workaround, you can declare a as volatile VALUE a; to turn off too much optimization. matz.