[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Memory woes
- From: Wim Couwenberg <w.couwenberg@...>
- Date: Sun, 2 Jul 2006 20:32:21 +0200
>> [...] Each time we do this cycle, memory associated with Lua has
>> increased 145KB to 155KB.
>> 6. The memory reported by lua as being in use doesn't change much (a few KB
>> between runs).
> As there are, as far as I know, no memory leaks in Lua, I would look
> at your memory manager for leaks.
I agree with Edgar on the "no memory leaks in Lua" part. Here are
just some random remarks, based on your observations:
1. It can take two subsequent gc cycles to collect everything. This
one is easy to check by doing a double gc when you start/quit your
2. If you have a stable life time cycle of objects, then Lua should
*not* report "a few KB" increase between runs (I gather your obtain
this via gcinfo), it should report the exact same amount. The GC in
Lua 5.0 runs atomically and is completely deterministic. Realloc-ing
to 0 (zero) as Edgar suggested cannot cause this increase.
3. A few KB increase in Lua objects can easily lead to an increase of
145 to 155 KB in allocated memory if some "heavy" userdata is not
collected that refers to C/C++ objects allocated outside the userdata.
Since Lua doesn't know about the size of such objects it cannot report
4. There *is* a way to create uncollectable cycles in Lua: if (k, v)
is a key value pair in a weak valued table and v refers (directly or
indirectly) back to k then that pair will never be removed from the
table, even if v is the *only* reference to k.