[luabind] 0.91 luabind::call_function - leak
Brought to you by:
arvidn,
daniel_wallin
From: Harakiri <iri...@ya...> - 2012-07-11 15:16:52
|
When i call a lua function with a non primitive object (e.g. not string, int) which class i registered to luabind - everytime i call the lua func, the memory usage increases. I have a loop, that calls the lua func 100k times - after that my usage increases by a few MB. The lua func is empty and does nothing. However, if call lua_gc(luaState, LUA_GCSTEP, 1); after every invoke, the usage does not increasse ( but at the end, 4KB remain no matter how many loop iterations i have - i gather this is the metatable for the object class that remains?!). Now when i use instead of luabind::call_function<void>(fn,MyObj); directly lua : // push function on stack fn.push(fn.interpreter()); luabind::globals(luaState)["MyObj"] = myObj; // put the obj onto the stack as func arg lua_getglobal(fn.interpreter(), "MyObj"); // call with 1 param lua_pcall(fn.interpreter(), 1, 0, 0); I dont need to use lua_gc(luaState, LUA_GCSTEP, 1) to have no leak at all after each invocation. (Moreover the performance increases massively, and cuts down execution time to half) Unrelated to call_function but to luabind in general, if i put multiple objects of the same class into the globals luabind::globals(luaState)["MyObj1"] = myObj1; luabind::globals(luaState)["MyObj2"] = myObj2; and delete the objects (and even NULL the luabind globals) - about 4k remain everytime (tho overwritting the same identifier does not increase it) - so for some reason it seems that luabind does not reuse the class metatable and creates a new one of each object? It seems once i registered an object with luabind, im unable to reduce the memory usage to the same it was before registering. |