lua-users home
lua-l archive

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


Hi,

The reference manual says:

2.10.1
"At the end of each garbage-collection cycle, the finalizers for userdata are called in reverse order of their creation, among those collected in that cycle."

Does this mean that sometimes userdata may not be collected in reverse order, i.e. when objects are collected in different cycles?

If this is the case, writing Lua bindings for complex C++ libraries just become more difficult in my mind. For example, there are typically all sorts of managers, and dependencies between objects that need to be teared down in proper order (reverse order of creation).

I'm asking this because I just hit a case that causes a crash in a C++ physics library when shutting down Lua. Basically there are a few manager objects which get collected before some other objects that have been created through the managers, and the physics library doesn't like that at all.

What would be the recommended practice to deal with these situations?

I'm using LuaJit-2.0-beta4 if that matters.

Best regards,

Petri Häkkinen