> This is basically what we do, except that the finaliser is the C function > itself. Do you mean that if I wrap the call the the C function in a lua > function, both - the finaliser and the ffi call - will be compiled? I think he means implementing a pool in Lua, so the function you pass to ffi.gc() is Lua all the way down. Assigning ffi.C.free() on ffi.gc(), with or without wrapping it into a Lua function, won't make the call compiled, but I think more importantly, will leave you out of memory pretty fast, because the gc doesn't know how much memory you've allocated on a single object (and unfortunately there's not API to tell it), and it needs that information in order to decide on the number of objects to be collected on a single step.