lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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