--f46d04447f4b861fbf04bd92705f
Content-Type: text/plain; charset=ISO-8859-1

I am running into a problem with to C extension objects and I'm not sure
what I'm missing. I put together a simple example illustrating the point
here:

https://github.com/linterra/ruby-c-ext-gc

Basically one C extension class (child) references another (parent). To
keep parent from being GC'd before the child referencing it, I assign a
reference in the child using rb_ivar_set(). Additionally, I also add a mark
function in the child to mark the parent.

Still, when GC runs, the parent still gets cleaned up first and the child
GC segfaults because it references the GC'd parent. I can see that the
child's mark function is being called.

So I am not sure what I am missing. What should I be doing to make sure the
child keeps a valid reference to the parent to ensure that it (parent) is
not GC'd before child?

I have tested this on Ruby 1.9.3 latest. 1.9.1 also exhibits the same
behavior. 1.8.6 It does not exhibit this behavior, but apparently because
it does not GC the child at all.

Any help would be greatly appreciated.

Mike

--f46d04447f4b861fbf04bd92705f
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I am running into a problem with to C extension objects and I&#39;m not sure what I&#39;m missing. I put together a simple example illustrating the point here:<br><br>https://github.com/linterra/ruby-c-ext-gc<br>
<br>Basically one C extension class (child) references another (parent). Toeep parent from being GC&#39;d before the child referencing it, I assign a reference in the child using rb_ivar_set(). Additionally, I also add a mark function in the child to mark the parent.<br>
<br>Still, when GC runs, the parent still gets cleaned up first and the child GC segfaults because it references the GC&#39;d parent. I can see that the child&#39;s mark function is being called.<br><br>So I am not sure what I am missing. What should I be doing to make sure the child keeps a valid reference to the parent to ensure that it (parent) is not GC&#39;d before child?<br>
<br>I have tested this on Ruby 1.9.3 latest. 1.9.1 also exhibits the same behavior. 1.8.6 It does not exhibit this behavior, but apparently because itoes not GC the child at all.<br><br>Any help would be greatly appreciated.<br clear="all">
<br>Mike<br>

--f46d04447f4b861fbf04bd92705f--