lua-users home
lua-l archive

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


Am 21.05.2014 23:44 schröbte Eric Wing:
Yes, I'm in the same boat. I'm just binding against other libraries
and don't necessarily control the API. And incidentally, SDL is one of
the libraries, but I discovered a bunch of unrelated libraries I'm
using have this same problem. And all the edge cases seem to keep
coming back to 2 extremes...fix GC or 100% manual management; a blend
of the two keeps causing me new edge problems.

I'd strongly suggest to fix GC -- dangling pointers and resource leaks are so un-Lua-like ...


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.

Nice thought.

So far I got away without this trick by controlling the order of construction (just require an argument of type B in the constructor of A and put it in A's uservalue table, and all is set), so I haven't tried it, but I think it should work.


I tried doing a simpler mockup to see what happens if I create
newuserdata during an object's finalizer. It looks like the problem is
still lua_close. But this time it looks like that lua_close may not
get around to cleaning up these new objects at all.

New objects created during the `lua_close` phase are not finalized. Last sentence of [1].


Thanks,
Eric


Philipp

  [1]: http://www.lua.org/manual/5.2/manual.html#2.5.1