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?:

  1. if array allocated using ffi.new('float[?]',n) gc can track references , collect necessary?
  2. using ffi.malloc(sizeof('float[n]')) must manually handled such ffi.free or provide "finalizer" such local p = ffi.gc(ffi.malloc(sizeof('float[n]')), ffi.free)?
  3. if library loaded ffi.load contained function float * example(void); , library loaded namespace ex in

    local ptr=ex.example()

    ptr storing pointer , when no references ptr exist, gc collect ptr , memory leaked?

  4. ffi.gc(ptr, ffi.free) lets garbage collector know ptr indeed pointer , memory points can reclaimed when ptr has no references?

in saying

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

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

php - Cannot override Laravel Spark authentication with own implementation -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -