From: ts Date: 2002-04-04T20:29:45+09:00 Subject: Re: Help: Ruby<->C++ callbacks >>>>> "L" == Luigi Ballabio writes: L> /* how to make sure the Ruby proc stays alive L> as long as we need it? L> Is the following the right way? */ L> rb_global_variable(p_); no, L> } L> /* how to make sure the Ruby proc stays alive L> as long as we need it? */ L> o.refCount_++; no, L> } When you return an object from your C++ code you must use Data_Wrap_Struct() or Data_Make_Struct() The 2nd argument of Data_Wrap_Struct (3rd for Data_Make_Struct) is the mark function which will be called when the GC mark the current object. Define such a function when you return a new object and in this function make a call to rb_gc_mark() to mark the Proc object Guy Decoux