lua-users home
lua-l archive

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


We're using Lua 5.0 in our runtime with tolua++, and I'm not sure that I understand some of the GC stuff I'm seeing.
 
Frequently (500-1000 times per second), our application runs a Lua function that has code like this:
 
function foo( )
 m = Matrix.new( )
 m = nil
 
 if g_collectNOW then
  collectgarbage( )
 end
end
 
Matrix.new() returns a userdata object. Lua's gc threshold starts out around 82k. We are pretty sure that there are no memory leaks on the C++ side of things.
 
If g_collectNOW is always true, memory stays at a consistent level.
If g_collectNOW is always false, memory grows linearly over time.
 
Question #1: Why does memory grow linearly over time? Shouldn't I see a sawtooth pattern of memory rising to a particular threshold, gc occuring, and memory dropping back down? I could even understand it (but not like it) if the sawtooth perhaps peaked at every-increasing values as the threshold got set to ever-increasing values. Instead, I see a constant linear growth, at the rate of a few megabytes per minute.
 
If I alternate g_collectNOW between false for a while (memory grows), then to true (gc every frame), the level that memory drops to for each gc-each-frame section is higher than the previous. Memory seems to be being irretrievably leaked.
 
Question #2: Uhm...what's going on? Where did that memory go, and why can't I get it back?

Thanks in advance for any help!

--
Gavin Kistner
.