lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


You're not the first to come across this. Unfortuanately, I don't know
of a good way to solve it (there is no neat way in standard Lua), but
you might want to take a look at this previous post:


> -----Original Message-----
> From: 
> [] On Behalf Of Cheng, Long
> Sent: vrijdag 14 november 2008 11:54
> To: Lua list
> Subject: gc problem when using lightuserdata to reference C++ objects
> Hi all:
> We are building a large mmorpg game using lua as the main language. We
> have a game engine built on C++. With a customize C++/lua binding, we
> could export the whole game object system to lua, and we write all the
> logic control code in lua. All the C++ objects are referenced 
> in lua as
> a lightuserdata, and their life cycle are controled by lua 
> code (objects
> are created by lua call to C++, and recycled by lua GC). Now 
> one problem
> I found is that, in most cases the C++ object is very big compare with
> the lightuserdata. When there are a big number of objects, 
> most process
> memory are occupied by the C++ objects, but not counted in lua VM. For
> example, in a typical situation the whole server process uses around
> 300M bytes but in lua "collectgarbage("count")" shows only around 30M
> bytes. In such case lua GC fails to reclaim the dead objects, because
> lua VM does not think there are enough "wasted memory" to reclaim. I'm
> just wondering is there any way I can tell the GC algorithm how much
> "external" memory the lightuserdata is referencing? Or is there other
> "proper" ways to handle the objects life cycle? Thanks!
> Regards
> Long