pinning objects in ffi.gc() finalizers

  • From: Cosmin Apreutesei <cosmin.apreutesei@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 2 Jul 2014 12:37:24 +0300

Hi,

I noticed that pinning objects in ffi.gc finalizers() doesn't work, at
least not when the program exits -- it's like the upvalues of the
finalizer are weak references. Is this a bug or a feature?

Example:

local heap = ffi.gc(CreateHeap(), FreeHeap)

local mem = ffi.gc(CreateMem(heap, size), function(mem)
  FreeMem(heap, mem) -- heap pinned in mem's finalizer
end)

When the program exits, sometimes heap's finalizer is called before
mem's finalizer, even though mem's finalizer pins heap.

Other related posts: