From: ts Date: 2004-07-30T23:56:41+09:00 Subject: Re: C ext: GC claiming objects early >>>>> "T" == Tilman Sauerbeck writes: T> rb_obj_call_init (rbres->self, 0, NULL); this is, no ? rb_obj_call_init(self, 0, NULL); T> static VALUE c_notifier_set (VALUE self) Well, you attach a notifier to an object but with the construct o.some_meth.notifier do |r| do_stuff_with(r) end this object is never stored in a variable, this is why ruby remove it Normally you must write it res = o.some_method res.notifier do |r| do_stuff_with(r) end and it will work, until ruby call the GC for `res' If you want to make it work like it is actually, you must store the result of `o.some_method' in an Array defined in `o' when #notifier is called, and mark this array. It will be marked when ruby will mark `o' Now the problem is here T> I _do_ want the GC to claim the object eventually, but not if the T> callback might still be called. How do you know that the callback might still be called ? Because if you use a method to release a notifier, then you just need an Array (defined with rb_global_variable()) which store the object when #notifier is called and remove it when you release the notifier Guy Decoux