lua-users home
lua-l archive

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


Hey everyone,

Is there any way to create a legitimate case when a table will never be collected (without the use of weak tables)? I have a case where tables refer to each other creating a bunch of cyclic references and the memory consumption seems to grow beyond reasonable point. It stops growing eventually at pretty high number. The way I attempt to get rid of such a hierarchy of tables is by removing the reference to its root, which I expected to have removed all cyclic references to the root and other tables within the hierarchy upon GC. It doesn't seem to do so even after calling collectgarbage() repeatedly. Hence my original question.

Thanks,
AB

>-----Original Message-----
>From: Mark Hamburg [mailto:mhamburg@adobe.com]
>Sent: Monday, February 09, 2004 8:21 AM
>To: Lua list
>Subject: Re: Weak tables, user data, and GC
>
>
>on 2/9/04 7:06 AM, Roberto Ierusalimschy at 
>roberto@inf.puc-rio.br wrote:
>
>> It is not uncommon to use a weaktable to associate attributes to
>> userdata (userdata is the key, attribute is the value). In 
>such uses, it
>> is also not uncommon that the finalizer code needs those 
>attributes. So
>> Lua does not remove those keys before calling the finalizer. 
>We assume
>> that this should not cause problems, because the only way to access
>> that pair would be using the userdata as a key, but as the 
>program does
>> not have access to that userdata anymore, it could not access that
>> entry. (Of course, that is not true if you traverse the table.  But
>> traversing a weak table is a tricky task anyway...)
>
>I realized that afterward and considered myself slapped for 
>iterating a weak
>table. My fix was to maintain a second table mapping the key objects to
>themselves. The value side of that table will be nil'd on the 
>first GC pass,
>so one can use this to detect finalized userdata without 
>adding an explicit
>"is_finalized" operation to the userdata.
>
>Mark
>
>
>