[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: again: problem with weak table and finalized objects
- From: Francesco Abbate <francesco.bbt@...>
- Date: Sun, 29 Aug 2010 18:44:22 +0200
2010/8/29 Luis Carvalho <lexcarvalho@gmail.com>:
> If I understand correctly your problem is not that the entries in your table
> are not collected when they're finalized, but that you're accessing already
> finalized windows. One workaround is to include a flag to your window object
> indicating if it has been finalized or not:
>
> for window, plot in pairs(weaktable) do
> if window.isdone() then
> -- do something
> end
> end
Hi Luis,
I think that what you are suggesting is not correct because if the
object have been finalized by Lua any access to read any flag is a
potential fault since the memory have been deallocated.
> If you really want to keep a "tight" correspondence between finalization and
> collection, use a regular table and free resources as needed:
>
> function finalizewindow (w)
> windowplottable[w] = nil
> w:free()
> end
Well, I was thinking to this kind of solution but I was interested to
understand why Lua was behaving that way. In the manual is written
that when the object is collected the pairs is automatically
eliminated from the table so I was wondering why I should remove it by
myself!!! :-)
Anyway, I think that I can adopt this solution if I don't find any
other solution.
Thank you for the help! :-)
Francesco