lua-users home
lua-l archive

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

在 2011-6-22 晚上9:02,"Duncan Cross" <>写道:
> On Wed, Jun 22, 2011 at 9:41 AM, Xavier Wang <> wrote:
> > I know I can make a table in registry to record the dependence of A and B,
> > but it wastes memory, and you can't collect the memory in a table has
> > dead-key, even it's a weak table!
> If you are really so worried about this you could periodically call
> something that copies the current contents of the dependence table to
> a new table and replaces it in the registry.
> > So is there any other way to tell lua this
> > dependence?
> No, since you rule out environment tables I don't believe there is any
> other way than using a weak table.
> -Duncan
Okay... thanks:)
But It seems that use weak table can only record oneside dependences: A depend B or B depend A, is it possible to make two side dependence using only one table?
I am maintain a tree,  that is, a node A can only have one parent, so I made a parent table to show the dependence:
Parent[A] = B -- meams B is the parent of A
So I can use one table, but I don't know to use weak key or weak value or others, since I want A and B depend each other. That means, only A and B all don't have reference, I can collect it, there is some mode like __mode="d" means the key and value are all weak and has depend to each other?