[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: problem with weak table and finalized objects
- From: Julio José Mora Salido <jmorasali@...>
- Date: Sun, 29 Aug 2010 16:04:19 +0200
Is it possible to don't send the mails to everybody all the time as it was before?
2010/8/29 Romulo <email@example.com>
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:
local w = getwindow()
-- do something that triggers the gc, like allocating lots of object
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 <firstname.lastname@example.org> 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,
Sent from my mobile device