From: ts Date: 2002-04-05T01:01:01+09:00 Subject: Re: Help: Ruby<->C++ callbacks >>>>> "L" == Luigi Ballabio writes: L> // the Callback constructor makes a copy of the VALUE pointing to L> // the proc and stores it away, but the Ruby interpreter doesn't know. irb> c = Callback.new(proc { puts "Hello World!" }) Well, here you return an object with its mark and free function L> // for all I know, here the interpreter could decide to gc the L> // proc object since the only reference that it saw is already L> // out of scope No. When the GC run it will mark all alive objects. This mean that it will mark the variable `c' (`c' is still in scope) and to do this it call the mark function that you have given in Data_Wrap_Struct. Because your mark function call rb_gc_mark() on the Proc object, the GC will not try to remove it (i.e. the Proc object is still alive for the GC) L> The question really was, how do I tell the interpreter that I'm holding a L> reference to a Ruby object from C++? You just define a mark function (given to Data_Wrap_Struct) and in this mark function you call rb_gc_mark() on all ruby object holding by C++ Guy Decoux