lua-users home
lua-l archive

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


On 06/26/2014 07:26 AM, Paige DePol wrote:
On Jun 25, 2014, at 11:26 PM, Daurnimator <quae@daurnimator.com> wrote:

Today I was reading the lua source, and came across this code in lmem.c ( http://www.lua.org/source/5.2/lmem.c.html#luaM_realloc_ )

     if (g->gcrunning) {
       luaC_fullgc(L, 1);  /* try to free some memory... */

Is that conditional accidentally reversed?
Why run the gc again ONLY if the gc is mid-run?
Wouldn't it make sense to run the gc if it's NOT already running?

Sorry if this is a stupid question >.<

Daurn.
If the realloc routine fails to allocate memory, and the garbage collector is running, then it will attempt to do a full garbage collection cycle (in emergency mode) in the effort to free memory.

The allocation is then tried again, and if it fails a memory error is thrown. If the garbage collector is not active then this emergency collection will not occur.

Note that the `g->gcrunning` flag only indicates if the garbage collector is running, not if it is in the middle of a run or any other status other than active or inactive.

~pmd



Now that explains why the emergency gc didn't run when I ran out of memory. I have disabled the GC and run it in steps when my system is idle.

Now I am wondering if there is an option to turn the GC of but still enable the emergency GC.
--
Thomas