Re: ffi.gc prevent collect object

  • From: Alexey Melnichuk <mimir@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 14 Nov 2013 16:54:28 +0400


> Finalizers for cdata objects are implemented with a weak-keyed
> table mapping to the finalizer function. I.e. there's a strong
> reference to the function. If it anchors the object through an
> upvalue then you get an uncollectable cycle.

> I think this is based on a misunderstanding on how cdata
> finalizers work: they already get passed the object as the first
> argument, there's no need to hold it in an upvalue. And no, you
> shouldn't (or can't) 'collect' auxiliary structures such as Lua
> tables. Finalizers are for resources, not for memory.

The problem is. For example: I have some handle (e.g. file) and i have Lua
object that use this handle (e.g. some database). Lua object has
close  method  that flush some cache to file before close this file.
So  i  need  call close method before close handle.
Lua 5.2 with it's ephemeron tables could collect this.
But Lua 5.2 has __gc method for tables.
May be i try use neworoxy function with __gc method for this.

> And since his mail provider holds a strong belief this list is
> spam, he'll never see the answer ... :-/

I do not get reply for my question, but i get your reply to
`Re: question about MIPS d­ynasm syntax` :)

I watch for mail list using http://news.gmane.org.

Thanks.


Other related posts: