From: Tony Arcieri Date: 2011-02-07T04:02:02+09:00 Subject: Re: C extension: How to check if a VALUE is still alive (not being GC'ed)? --0016e6de0164fee6a8049ba1bffc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sat, Feb 5, 2011 at 4:02 PM, I=F1aki Baz Castillo wrote: > The problem is that the VALUE could be GC'ed (or being marked for so) > if the programmer assigns it to "nil" before the callback is executed, > so we get a coredump. > > So when the callback is executed I need to check that the given VALUE > is still alive (not GC'ed neither marked for being GC'ed). How can I > inspect that? (I mean in C). How is rb_gc_mark() insufficient here? Marking prevents objects from being GCed... you seem to be suggesting it's the other way around. If you mark all VALUEs your C extension is internally referencing in your C extension's "mark" function it will prevent them from being garbage collected. As Peter said though, if you use rb_iv_set, you get this behavior for free as Ruby automatically marks instance variables for you. --=20 Tony Arcieri Medioh! Kudelski --0016e6de0164fee6a8049ba1bffc--