From: Richard Dale Date: 2004-07-30T06:36:45+09:00 Subject: Re: C ext: GC claiming objects early Sean O'Dell wrote: > On Thursday 29 July 2004 13:11, Tilman Sauerbeck wrote: >> >> I know I can work around this by using rb_global_variable() to tell the >> GC not to claim the object, but this kinda sucks since the object will >> never be freed :( >> >> So, my question is: how do I prevent the Result object from being >> claimed by the GC without using rb_global_variable's? > > If this object is a VALUE variable in your C code, you should declare it > this way: > > volatile VALUE result = Qnil; > > Adding volatile allows the GC to see the object on the C stack. This > means that so long as your C code holds it in that variable, it will never > go away. What about using rb_gc_register_address() to ensure the result object isn't gc'd? VALUE Result; .... rb_gc_register_address(&Result); -- Richard