c - LuaJIT pointers and Garbage Collection -
i trying understand luajit's garbage collector handle ffi , have manage manually sure no leakage.
reading luajit ffi semantics docs garbage collector following assertions true?:
- if array allocated using
ffi.new('float[?]',n)
gc can track references , collect necessary? - using
ffi.malloc(sizeof('float[n]'))
must manually handled such ffi.free or provide "finalizer" suchlocal p = ffi.gc(ffi.malloc(sizeof('float[n]')), ffi.free)
? if library loaded ffi.load contained function
float * example(void);
, library loaded namespaceex
inlocal ptr=ex.example()
ptr
storing pointer , when no references ptr exist, gc collectptr
, memory leaked?ffi.gc(ptr, ffi.free)
lets garbage collector know ptr indeed pointer , memory points can reclaimed when ptr has no references?
memory areas returned c functions (e.g. malloc()) must manually managed, of course (or use ffi.gc()). pointers cdata objects indistinguishable pointers returned c functions (which 1 of reasons why gc cannot follow them).
is meant though namespace c library functions given ffi in knows return value pointer, garbage collection cannot act autonomously performing (4)?
what meant mike pall when says
"but if function [ffi.gc()] compiled ... gc have call finalizer eventually, costly."
is referring function call ffi.free
in case? if so, how ffi.new
around overhead?
Comments
Post a Comment