lua-users home
lua-l archive

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


Am 21.05.2014 11:43 schröbte Eric Wing:
Thank you for all the responses. That clears a lot up. Thanks for
mentioning the lua_close case too. That insight was also valuable.

So I went with a luaL_ref/luaL_unref workaround which solves
everything but the lua_close case.

I had the idea of iterating through the _G table and setting all the
references to nil and forcing garbage collection before close, but in
testing, I noticed there were a lot of local "global" variables in use
in my programs which I can't reach. Any other ideas along these lines,
perhaps using the debug library?

A weak table where all A objects register themselves?

I have another idea: What about splitting the A objects into two objects A and A_finalizer. The A_finalizer only lives in A's uservalue table, so it usually will become garbage at the same time as A. Whenever you associate a B object with the A object, you "disarm" the old A_finalizer, create a new one, and put both the B object and the new A_finalizer in A's uservalue table. Since the A_finalizer was created after the B object, it will be finalized before it.


Thanks,
Eric


Philipp