lua-users home
lua-l archive

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


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
>