lua-users home
lua-l archive

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


Hi,

I use lua 5.0.3 in my app.
The app works for days and it leakes memory.

The amount of the memory returned by gcinfo() grows about 10 MB / 24 h.
Calling collectgarbage() (even multiple times) doesn't help. Gcinfo()
indicates it continues to grow.

I thought that some global tables grow therefore I counted entries in _G
with the code is on the end of this email.

The number of globals is constant and yet the lua GC grows ( gcinfo() ) .
So I dig into lua source and found out that the collected elements are in
L->l_G->rootgc  and ->rootudata

I think I can iterate over them by next_elem = cur_elem->gch.next . Is that
correct?


But how can I get type of the element?

Thanks Nick


-----------COUNTING GLOBALS -----------------
function count_table( t )
  local il=0
  local a,b
  for a,b in pairs(t) do
    il=il+1
    if(tolua.type(b)=="table"  and not(a=="_G") and not(a=="__index") ) then

      il=il+  count_table(b)
    end
  end  
  return il
end

function count_globals()
	count_g=0
	print("--------------", os.date(),"   ----------")
	count_g=count_table(_G)
	print("NUMBER of globals:", count_g)
	collectgarbage()
	collectgarbage()
	local a,b=gcinfo()
	print ("MEM: ",a,"  KB")
end

count_globals()