lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


If I move the invocation of __gc from GCTM to luaC_separateudata, I
get the desired behavior - but what implications does that have on the
collector?

Pablo

On Tue, Aug 10, 2010 at 11:18 AM, Pablo Pissanetzky <pablo@trickplay.com> wrote:
>> The object has been marked for finalization. It will be finalized no
>> matter what, so you should not use it anymore. That is why it is removed
>> from weak tables.
>
> There is no way for me to know that the object has been marked for
> finalization - so I can't stop using it.
> I rely on __gc being called to give me this information. The fact that
> its corresponding key is no longer in
> the weak value table can give me a hint, but it is not reliable. It is
> entirely possible that the key has been
> re-used and now points to a completely different user data.
>
>> Why do you need that reference?
>
> In my system, we are using a toggle reference to bind to ref counted
> objects (GObject). The user data has a
> strong ref to the underlying object. The object, in turn, toggles
> between a weak ref and a strong ref to the
> user data. (It is weak when the user data's ref is the only one and
> strong when there are others). This works
> well but relies on the weak ref to the user data sticking around until
> __gc is called.
>
> See http://www.mail-archive.com/gtk-devel-list@gnome.org/msg00544.html
>
>
>
>
> On Mon, Aug 9, 2010 at 2:44 PM, Pablo Pissanetzky <pablo@trickplay.com> wrote:
>> This is what I'm seeing:
>>
>> 1. In one pass of my event loop, I create a user data and add it to a
>> table as a weak value (the key is an integer).
>>
>> 2. In the next pass of the event loop, I create another one and add it
>> to the same table. At this point, the first one I added is removed,
>> but that user data's __gc has not been called. Control, returns to me.
>>
>> 3. In the next pass of the event loop, I expect the first one to still
>> be there (because it has not been finalized), so I look for its
>> (integer) key in the table and it is not there.
>>
>>
>> It seems like there are two distinct steps: 1. Remove weak k/v pairs
>> when the value is weak. 2. Call __gc later.
>>
>>
>> I'm trying to maintain a weak reference to the user data until _gc is
>> called. Is there another way to do it?
>>
>> Pablo
>>
>> On Fri, Aug 6, 2010 at 5:31 PM, Pablo Pissanetzky <pablo@trickplay.com> wrote:
>>> (In 5.1.4)
>>>
>>> If I have a weak ref to a user data (as a value) in a table, is it
>>> possible for the weak ref to be removed long before the userdata's
>>> __gc metamethod is called? Does this happen in multiple passes of the
>>> collector?
>>>
>>> Thanks in advance,
>>> Pablo Pissanetzky
>>>
>>
>