From: Ammar Ali Date: 2012-04-17T03:54:01+09:00 Subject: Re: C extensions: disable GC for a Ruby object and enable GC later for it On Mon, Apr 16, 2012 at 9:31 PM, IƱaki Baz Castillo wrote: > Hi, I do know this is very commented subject but I don't understand it clearly: > > I'm coding a Ruby C extension which usess Ruby objects (Proc objects, > class instances...) asynchronously, which means that I need to tell CG > not to try those objects until I use them so they can be GC'd. > > Could I know which two C functions should I use?: > > 1) a function for avoiding GC on a given Ruby object (VALUE). > 2) a function to re-enable GC on a given Ruby object (VALUE). There are at least a couple of ways. One is to decalre these objects as global variables, but that means they will live for the life of the program (i.e. no GC until the end) rb_global_variable Another way is to register the address with GC. I think this is closer to what you are asking for: rb_gc_register_address and rb_gc_unregister_address. Note that these take a pointer to VALUE, not just a VALUE. HTH, Ammar