From: "Iñaki Baz Castillo" Date: 2012-05-18T07:34:33+09:00 Subject: Re: rb_gc_register_address() or rb_gc_mark()? 2012/5/18 Eric Hodel : > To do this you use rb_gc_mark(the_struct->my_string).  Without calling rb_gc_mark the garbage collector may reclaim your string which can lead to a crash the next time you try to use it. Sure, it's fully understood now, and in fact, without the mark crashes occur. Now my other question is about the undocumented rb_gc_register_address(VALUE object). As per my experience, this is only valid for VALUE created within ruby code, and not for Ruby objects that run in Ruby land. For example, in my C extension XXXXX_init() function I create a Ruby String which I use within my C code: VALUE string_aaa = rb_str_new2("aaa"); So I must add: rb_gc_register_address(&string_aaa); Otherwhise it's GC'd. But if I try to do the same with a previously existing Ruby object (created in Ruby land or referenced in Ruby land) then rb_gc_register_address does nothing. For example: VALUE MyClass_do_domething(VALUE self) { rb_gc_register_address(&self); return self; } This does NOTHING. The object (self) will be GC'd as usual. -- Iñaki Baz Castillo