lua-users home
lua-l archive

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

Ahhh... thank you very much.

So, is it true that having a SCRIPT loaded (and a reference to it saved), is
not enough to prevent the STATE in which it is loaded from being GC'd?

I guess this was my incorrect assumption.

>>You're confusing the two separate things which you need to keep track

- The child state itself. This is the object that is pushed onto the
  stack as a result of calling lua_newthread. Even though you have a
  C-side pointer to this object (a lua_State), it is still subject to
  being GCed if you don't save the 'Lua half' of it somewhere, at
  which point the C-side pointer will be left dangling, hence the
  crash. Doing a luaL_ref on that object will indeed preserve it, but
  it doesn't sound like you're doing that. So, this is being GCed. You
  need to add refs and unrefs for this object.

- The script which will be run in the child state. You're saving a
  reference to this, and it won't be GCed unless you unref it again
  /even if the state it was going to run in has been GCed/. Hence the
  creeping memory usage you saw. You're treating this object
  correctly, but seeing problems when you try to unref it because of
  the above.