From: "Iñaki Baz Castillo" Date: 2012-05-18T04:19:29+09:00 Subject: Re: rb_gc_register_address() or rb_gc_mark()? 2012/5/17 Iñaki Baz Castillo : > - MyClass_alloc() function mallocs a C struct. > - The C struct contains a "my_string" VALUE field and I assign there > i.e. a Ruby String (which does not exist in Ruby land). > - Of course MyClass_free() function should free the C struct. > > But, what about "my_string" VALUE within the C struct? > > - Let's say that I've an instance of MyClass in a global variable $my_class. > - Then I run GC.start. Would it free my_string VALUE? (yes/no) > - In case of yes, should then I provide a MyClass_mark() function > which does this?: > >    rb_gc_mark(data->my_string) Ok, after some experiment I'm confused: - I run GC.startt every 0.1 seconds. - While my_class instance (which wraps the C struct referencing my_string VALUE) remains in the scope (or stored in a global variable) my_string is NOT GC'd. I know it because I've stored its object_id and used it in ObjectSpace._id2ref(id) and it returns my_string. So... even if I've seen the usage of rb_gc_mark() in some C extensions, in my experiments it does nothing. Any help would be appreciated. Thanks a lot. -- Iñaki Baz Castillo