Re: cdata finalizer called twice

  • From: Mike Pall <mike-1411@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 13 Nov 2014 19:54:28 +0100

Peter Colberg wrote:
> On Thu, Nov 13, 2014 at 11:47:43AM +0100, Mike Pall wrote:
> > This looks suspicious: 'event' is not anchored and you create a
> > new cdata pointer object from it with 'event[0]', which has the
> > finalizer attached.
> 
> event[0] is of type pointer, so LuaJIT implicitly makes a copy.

ffi.gc() only attaches to the cdata pointer object you pass to it.
Only the lifetime of this *object* decides when the finalizer is
called. It doesn't matter which other pointers you have around
that point to the same address.

Oh, and ... maybe you missed it, because my answer was so lengthy,
but 'event' is unanchored. Anything can happen if you do that.

--Mike

Other related posts: