lua-users home
lua-l archive

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


>>>>> "Flyer31" == Flyer31 Test <flyer31@googlemail.com> writes:

 Flyer31> I tried the following C code:

 Flyer31> lua_State* LuaBase= luaL_newState();
 Flyer31> luaL_dofile( LuaBase, "test.lua");
 Flyer31> for( int i= 0; i< 100; i++){
 Flyer31>   lua_State* L= lua_newthread( LuaBase);
 Flyer31>   lua_resetthread( L);
 Flyer31> }

 Flyer31> If I watch LuaBase->top in this for loop, it will increase and
 Flyer31> increase. Is there some recommended way to avoid this? (thus
 Flyer31> to somehow "remove the new thread" again completely?).

lua_newthread pushes the Lua value of the new thread onto the stack of
the calling thread (LuaBase in this case). If you're not going to make
use of it, you need to pop it off the stack, _after_ the resetthread
call since once it is off the stack it may be garbage collected (so you
can't assume L is valid once there are no more references to the
thread).

As written, your above code is just letting thread objects accumulate on
the stack.

-- 
Andrew.