c++ - Lua garbage collection and C userdata -
in game engine expose vector , color objects lua, using userdata.
now, every locally created vector , color within lua scripts, luas memory usage goes bit, doesn't fall until garbage collector runs.
the garbage collector causes small lagspike in game.
shouldn't vector , color objects deleted if used arguments? example like: myobject:setposition( vector( 123,456 ) )
they aren't right - memory usage of lua rises 1,5 mb each second, lag spike occurs , goes 50kb.
- how can solve problem, solvable?
in lua, way object userdata can deleted garbage collector. can call garbage collector directly, b mitch wrote (use lua_gc(l, lua_cgstep, ...)
), there no warranty temporary object freed.
the best way solve avoid creation of temporary objects. if need pass fixed parameters methods setposition
, try modify api accepts numeric arguments, avoiding creation of temporary object, so:
myobject:setposition(123, 456)
Comments
Post a Comment