From: Eric Hodel Date: 2011-02-09T09:21:04+09:00 Subject: Re: C extension: How to check if a VALUE is still alive (not being GC'ed)? On Feb 8, 2011, at 3:18 PM, Iņaki Baz Castillo wrote: > 2011/2/8 Eric Hodel : >>> Yes, that's work: the resolver object contains a hash attribute in >>> which queries are stored until completed. >> >> Use a ruby hash and supply mark and GC callbacks to Data_Wrap_Struct so the GC will keep track of it. > > Thanks, but I don't understand why I must use mark callback: > > - My class uses Data_Wrap_Struct containing a xxx_free function to > free the C structure when the object is GC'ed. > > - An instance of my class contains an @hash attribute (which is set > empty in initialize method). > > - Such @hash is populted with some normal Ruby objects during runtime. > Nothing special here. > > - So when my instance is GC'ed, at some point Ruby will GC the @hash > attribute and also the objects it contains. > > Then... why do I need a mark callback? Maybe I miss something, however > Itested my code under high load and doesn't seem to leak. > Thanks a lot. Since you use the instance variable you do not need the mark callback. The mark callback is only required if you are storing ruby objects in a structure that hides them from ruby.