lua-users home
lua-l archive

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


2010/8/2 Benoit Germain <bgermain@ubisoft.fr>:
>
> My guess is this isn't a Lua bug. Your "plot" and "line" objects most likely get collected during the same cycle, since when the "plot" becomes unreachable, its "lines" become unreachable too at the same time. Doc says that during a collection cycle, userdata are collected in reverse creation order, so it is the expected behavior.
>
> What I would do to solve this is store all lines belonging to a plot in some table, but instead of this being the plot's environment, use your plots as weak keys to these tables in an ephemeron table stored in the registry, thus causing plot finalizers to be called before the lines are destroyed (see §2.5.2).

Hi Benoit,

thank you very much, this is very helpful. Actually I was thinking the
same things: the objects get collected in the same GC cycle and Lua
does not care if one references the other or viceversa.

I will probably adopt your suggestion and use a weak table to maintain
a list of references.

Thank you very much for your help.

Francesco