[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT FFI and __gc metatable
- From: Mike Pall <mikelu-1204@...>
- Date: Wed, 4 Apr 2012 00:40:02 +0200
Pavel Roschin wrote:
> local ptr = ffi.new('Image')
> ptr:draw() --works
> ptr = nil --works perfectly, lib.deleteImage works
> -------------------------
> local ptr = lib.newImage()
> ptr:draw() --works as previous
> ptr = nil --here is no __gc call!
> collectgarbage() --still nothing
The __gc metamethod is only called for cdata that is allocated by
LuaJIT itself. For pointers to data allocated on the C side, you
need to use ffi.gc(ptr, finalizer). The idiom to use is:
local ptr = ffi.gc(lib.newImage(), lib.deleteImage)
--Mike