lua-users home
lua-l archive

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

> > So perhaps these circular references (child has
> > reference to parent which prevents collection of
> > parent) are blocking the collection. But in this case I 
> > thought that countreferences would give me the count of the 
> > references caused by these closures.
> It certainly seems that the child objects having a reference 
> to the parent via an upvalue is what is preventing 
> collection. I temporarily changed the code so that the parent 
> referencing closures are not created and now all three 
> userdata objects get collected as required.
> Of course now the code doesn't work but there should be a way 
> around that and I am one step closer to fixing the issue.

I have fixed the problem. The container objects (the parents) were not
getting collected since their child objects (UI buttons) had their
parent as an upvalue in a callback closure. This reference is not
getting reported by countreferences.
However, adding code that removes the button callbacks from the callback
list before setting the parent container references to nil allows the
callbacks to be collected, which in turn allows all the parent
containers to be collected. Hooray!!

I don't know about anyone else, but managing references so that objects
that *must* be collected actually *are* collected has probably been the
biggest stumbling block I have encountered in this project.

- DC

PS: Sorry for answering my own posts. It's just that I solved this issue
before anyone else had a chance to respond, so I thought I better post
that it was solved.