lua-users home
lua-l archive

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


No. Weak tables are weak references to objects. This means, in simple
terms, that when the garbage collector is trying to find any reference
to object, to decide if the object will be collected or not, the weak
reference won't count. However, there are times when the collector
needs more than one pass to determine if it shall collect the object
or not. Unfortunatelly, I have next to nothing knowledge of the
execution semantics of the collector.
I also recommend that you check if there are no other references to
the said window elsewhere, like temporary local variables, function
arguments, registry maps etc. I think it may happen that the collector
could be called while you are inside a function with said locals
referencing the window, such as:

do
local w = getwindow()
w:destroy()
-- do something that triggers the gc, like allocating lots of object
traverse_the_reverse_lookup_table()
end

In this particular case, 'w' holds a hard (i.e.; not weak) reference
to the window. This reference lives untill becoming out of scope,
usually when the function returns.

On 8/28/10, Francesco Abbate <francesco.bbt@gmail.com> wrote:
> Hi all,
>
> I've got a dirty problem using weak tables, I hope someone can help
> me. What I'm doing is to keep a table that map windows objects to plot
> objects using the windows as weak keys. In some cases I'm doing a
> reverse lookup on this table to find out which window is referencing a
> particular plot.
>
> What troubles me is that in same cases the table still contain among
> the key some windows that are already finalized. I was thinking that,
> because the keys are weaks, they are eliminated from the table when
> the GC finalizes the object. The problem is that it does not seem to
> work that way and sometimes I can access an object already finalized.
>
> Thank in advance for the help.
>
> Best regards,
> Francesco
>
>

-- 
Sent from my mobile device