[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua from C
- From: Tim Hill <drtimhill@...>
- Date: Wed, 17 Dec 2014 17:31:49 -0800
> On Dec 17, 2014, at 2:21 PM, Lev <firstname.lastname@example.org> wrote:
> I tested the memory allocation with valgrind, and it seems there is no extra
> memory allocated after each run. If there's any other tool that can detect
> such leak, please let me know.
No you won’t be leaking memory (unless you have a bug in your own C code!). My point about the extra garbage collect was purely addressed at housekeeping. Lua will eventually perform a GC and recover memory without any help from you. However, imagine that your script allocates a large table during processing, then sets this table to nil just before one of your 100ms “ticks” finishes (and the script ends). This table is of course a candidate for collection, and will be collected _at some point_, but it’s quite possible that this will not happen until the next (or later) 100ms tick (remember Lua has no autonomous GC thread, so it can only collect while a script is running or (in some cases) when you call the Lua API).
What this means is that garbage left over from one of your script 100ms “ticks” might not be collected until the next “tick”. If you ok with that, great, but if you are concerned about that memory not being released for use (say) by the C code, then you should call the lua_gc() API to trigger a collect when your script returns.