lua-users home
lua-l archive

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


> 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.

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.


> It seems like there are two distinct steps: 1. Remove weak k/v pairs
> when the value is weak. 2. Call __gc later.

Lua's collector is incremental, so these steps are not exactly distinct,
but are not atomic either.


> I'm trying to maintain a weak reference to the user data until _gc is
> called. Is there another way to do it?

Why do you need that reference?

-- Roberto