#ffi memory management (destructor with gc)

1 messages · Page 1 of 1 (latest)

tulip tapir
#

In LuaJit FFI, there is ffi.gc() to use auto memory management with c-ffi allocated object. I heard N-API's ObjectWrap has same function.

How can I treat it in bun, to go nice with GC and C's alloc / free or C++'s constructor and destructor via bun:ffi?

slow sigil
#

preferably you should do manual freeing when possible to not put pressure on gc and memory

#

gc is not aware of how much memory your ptr is worth so it might put off doing garbage collection for very long time

#

one way to fix that is to allocate memory on javascript side and give the pointer to c

#

but you have to keep reference to that slice somewhere or it will become dangling pointer