From f399e6705fab15013ae468049c910577e1a9a5a1 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 24 Apr 2017 14:52:18 -0300 Subject: [PATCH] ensures that "collectgarbage'step'" in generational mode does a minor collection --- lgc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lgc.c b/lgc.c index d27ea42b..692326f3 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.224 2017/04/20 18:24:33 roberto Exp roberto $ +** $Id: lgc.c,v 2.225 2017/04/24 16:59:26 roberto Exp $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -1202,13 +1202,18 @@ static void fullgen (lua_State *L, global_State *g) { /* -** Does a generational "step". For now that means a young -** collection. (We still has to implement the full control.) +** Does a generational "step". If memory grows 'genmajormul'% larger +** than last major collection (kept in 'g->GCestimate'), does a major +** collection. Otherwise, does a minor collection and set debt to make +** another collection when memory grows 'genminormul'% larger. +** 'GCdebt <= 0' means an explicity call to GC step with "size" zero; +** in that case, always do a minor collection. */ static void genstep (lua_State *L, global_State *g) { lu_mem majorbase = g->GCestimate; //lua_checkmemory(L); - if (gettotalbytes(g) > (majorbase / 100) * (100 + g->genmajormul)) { + if (g->GCdebt > 0 && + gettotalbytes(g) > (majorbase / 100) * (100 + g->genmajormul)) { fullgen(L, g); } else {