lua-users home
lua-l archive

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


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