|
I'm using tolua++1.0.93, and lua-5.1.4 (CEGUI 0.84 dependencies). I have been tracking this nasty memory leak for couple of hours, and I've found that toluapp creates tolua_gc table in Lua registry and it seems that this table grows infinitely.
When I push my object to Lua using tolua_pushusertype_and_takeownership I want Lua's GC to delete my object. And it does so, but tolua_pushusertype_and_takeownership calls tolua_register_gc which puts this objects metatable under object as a key to this "global" tolua_gc table. When tolua_gc_event function calls collector function (which calls delete operator) it that sets nil value to tolua_gc table under just deleted object as a key. So that should work, right?
Well, no.
Maybe I understood something wrong, but it seems that this has no effect on size of the tolua_gc table. I have also tried to manually call tolua.releaseownership(object) from Lua. And it worked. I mean, it decreased memory used by Lua (LUA_GCCOUNT) but since it disconnected collector from object, operator delete is never called and it created memory leaks in C++.
It is really strange behavior, because all tolua.releaseownership does is it sets nil value to tolua_gc table under passed object as a key. So why tolua.releaseownership decreases size of memory used by Lua, and tolua_gc_event does not? The only difference is that tolua.releaseownership calls garbage collector before it sets nil to tolua_gc table, and tolua_gc_event is called by garbage collector (opposite situation).
Why do we need that global tolua_gc table? Can't we just take metatable from object directly at the moment of collection?
I have really limited memory that I can use from this process (8MB) and it seems that this tolua_gc table occupies like 90% of it after some time.
How can I fix this?
I'm open to make any necessary changes to tolua source.
Thank you.