Read in Python CFFI documentation:
The interface is based on LuaJIT’s FFI (...)
Read on LuaJIT website (about ffi.gc()
):
This function allows safe integration of unmanaged resources into the automatic memory management of the LuaJIT garbage collector. Typical usage:
local p = ffi.gc(ffi.C.malloc(n), ffi.C.free)
...
p = nil -- Last reference to p is gone.
-- GC will eventually run finalizer: ffi.C.free(p)
So, using Python-CFFI, do you have to trigger the destruction of the last reference to a variable instantiated using ffi.gc
(= that needs a special function for deallocation because some parts of it are dynamically allocated) by setting it to (i.e.) ffi.NULL
?