Sharing a C object across different lua_States

  • From: Jeff Slutter <jeff@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sun, 26 Aug 2012 21:28:28 -0400

I'm curious if the garbage collector is per-lua_State, or across the
entire process.

For example, if I have two lua_State states (StateA & StateB), and
allocate an ffi struct using ffi.new in StateA. Then, through some
means, get that pointer to StateB for it to use, and then drop my only
reference to it in StateA, will the GC think that data is no longer in
use and free the resource, or will it see that it is still in use in
StateB (assuming I hold a reference in the state)?

One example of this is in William Adam's [great] blog post here:
http://williamaadams.wordpress.com/2012/04/06/passing-parameters-while-creating-threads/

It is obviously working for him (or, so I guess, I know he is on the
mailing list), but I want to make sure it is a safe idea. Well, at least
that the GC won't pull the rug out from under me.

Other related posts: