On Wed, Aug 27, 2014 at 2:35 AM, Nick Wellnhofer <[email protected]> wrote:
> On 27/08/2014 08:14, Marvin Humphrey wrote:
>>
>> Haha, this is backwards from how I would have conceived it -- I figured
>> we'd
>> keep a list of host objects only referenced from C-space.
>>
>> I think this means we have to differentiate between these two situations:
>>
>> * refcount falls to 0 but host wrapper is still live so don't invoke
>> Destroy.
>> * refcount falls to 0 and no host wrapper exists so invoke Destroy.
>
>
> Exactly.
> OTOH, this might allow us to use the host language's GC for all Clownfish
> objects and make refcounting a no-op which seems like an interesting idea.
We should explore every option to make that work -- it's the ideal.
But consider the challenges posed by a concurrent collector which might fire
at any time.
void
Foo_print_self(Foo *self) {
String *str = Foo_To_String(self);
// Collector fires now.
printf("%s\n", Str_Get_Ptr8(str));
DECREF(str);
}
When GC runs, the variable `str` is only referenced from the C stack. It
will be released, resulting in a dangling pointer.
Marvin Humphrey