Re: Making FFI callbacks call free() automatically when it's collected

  • From: Johnson Lin <arch.jslin@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 20 Jul 2012 21:44:23 +0800

2012/7/20 Johnson Lin <arch.jslin@xxxxxxxxx>:
> Thanks again for the guidelines, I'll adjust accrodingly.
> As a side note, after reading this:
> and related links in the page...
> I am more and more convinced that it is not worth the effort. I'll
> still try some simplified kind of "scope" thing, it only has to fit my
> current needs, but if I can't get that done I think then manual
> management is still the only sensible way to go.
> Other game engines like CoronaSDK, which binds Lua to C/C++ codebases
> have this problem too. An image object in Corona has to call
> obj:removeSelf() to really remove its image/texture from the engine,
> you just cannot rely on GC / finalizers for that in a straightforward
> way. I think it just happens, whenever Lua has access to outside
> resources.
> best,
> Johnson

Oh, forget to mention why I still say that even though I got the
callbacks mapping working.

The problem is essentially the same as before, just the subject now is
not the callback, but the object itself --- even though I can
correctly remove callbacks when the object finalizes by checking the
obj-to-callback mapping table, the garbage collector's behaviour is
not predictable as always, unless resorting to use collectgarbage().

And there's a lot of callbacks I am allocating in the UI. At least
dozens per menu. So when GC is not collecting for a while, it still
hits the FFI callback limit in the LuaJIT.


Other related posts: