> If I understand what you're saying; Lua is blind to the fact that B has a reference to A
> that should prevent A from being garbage collected
I still want the __gc metamethod associated with "A" to be called so I know when there are no references to it other than "B", but I need to stop lua from freeing "A" memory until "B" has completely removed "A" reference(Assume that "B" is a collection of objects of type "A")
> You could create a table entry somewhere that has B as a (weak) key and A as the value. In function "C", remove the table entry. So long as B exists then so does A, because of the table entry you created. If either C is called or B itself is garbage collected, then the table row is removed and A becomes eligible for garbage collection.
I'm more interested in deferring "A" garbage collection. For this problem, we can even assume that "B" is never garbage collected.