0.91 luabind::call_function - leak

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

0.91 luabind::call_function - leak

Harakiri-2
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.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: 0.91 luabind::call_function - leak

Willi Schinmeyer
 > 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?!).

Does starting garbage collection once after the whole iteration remove
the excess memory, too? In that case the garbage collection was just not
being invoked since Lua didn't mind the couple of MBs enough yet to
bother collecting them.

 > It seems once i registered an object with luabind, im unable to
reduce the memory usage to the same it was before registering.

Because a metatable with class-related information gets stored in the
registry. That's normal. There's no way to unregister something.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: 0.91 luabind::call_function - leak

Harakiri-2
--- On Wed, 7/11/12, Willi Schinmeyer <[hidden email]> wrote:

> From: Willi Schinmeyer <[hidden email]>
> Subject: Re: [luabind] 0.91 luabind::call_function - leak
> To: [hidden email]
> Date: Wednesday, July 11, 2012, 11:22 AM
>  > 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?!).
>
> Does starting garbage collection once after the whole
> iteration remove
> the excess memory, too? In that case the garbage collection
> was just not
> being invoked since Lua didn't mind the couple of MBs enough
> yet to
> bother collecting them.

No - thats the issue - everything remains - only gc step will help after each invocation - a full GC after all invocations will not clear the memory.

> Because a metatable with class-related information gets
> stored in the
> registry. That's normal. There's no way to unregister
> something.
>

Yes - normal - but it would only be normal that for each class 1 metatable exist - however it looks like for each object of class A a new metatable is created. This makes no sense.



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user