[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: problem with weak table and finalized objects
- From: Francesco Abbate <francesco.bbt@...>
- Date: Sun, 29 Aug 2010 18:08:01 +0200
first of all thank you for your help.
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.
I'm starting to think that it is like you say, the "weak" character of
keys of values it just affects the decision of Lua to collect the
objects or not, but I've read carefully the reference manual about
that and it says:
"In any case, if either the key or the value is collected, the whole
pair is removed from the table."
So I was not wrong when I understood that the pair is removed
immediately when the object is collected.
> 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:
actually this is not the case, there are no references to the object
except for the weak key in the table. Actually this needs to be true
because Lua is actually *collecting* the object so there are really no
references to the object neither it is in the stack. I've also made
some tests and I've seen that the pair is actually removed from the
weak table if a new full gc cycle is requested.
What I guess is that the Lua behaviour is not strict about pair
removal from table because this kind of feature is hardly used by
other applications. I believe that actually most mixed C/C++/Lua
applicatons just use reference counting and they have no problems.
I've changed recently the approach from reference counting to full Lua
object managements for my C++ objects and I've got a lot of problems
but I'm confident I'm going to make it works :-)