lua-users home
lua-l archive

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


Hi Carsten,

On Thursday, August 23, 2007 1:56 AM, Carsten Fuchs wrote:

> Hi Vijay,
> 
> 
> I did, but...
> 
>> "A weak table can have weak keys, weak values, or both. A table
>> with weak keys allows the collection of its keys, but prevents
>> the collection of its values. A table with both weak keys and
>> weak values allows the collection of both keys and values. In
>> any case, if either the key or the value is collected, the
>> whole pair is removed from the table.
> 
> ... if I understood the last statement correctly, I think that
> there still is a problem: 
> If I have TableInRegistry have weak keys (but normal, i.e.
> non-weak, values), the key-value pairs can be collected ahead of
> time, because there are no other references to the keys (which
> are the "thread" objects that I want to anchor in the first
> place).    
> 

I think you are right. I have a vague memory of someone posting a
requirement similar to yours and how the list responded by saying
that one should use weak tables. May be you can do a search for
'weak key' in the list.

I think if it was user data then one can store a pointer to the user
data as both key and value in a weak keyed table. Then when the
value is set to null the GC should kick in. I will admit this is not
my turf - but I want to learn this stuff anyways; so I stuck my neck
out. Good luck with your project.

-- Vijay