示例#1
0
void lua_close() {
    TaggedString *alludata = luaS_collectudata();
    GCthreshold = MAX_INT;  // to avoid GC during GC
    luaC_hashcallIM((Hash *)roottable.next);  // GC t.methods for tables
    luaC_strcallIM(alludata);  // GC tag methods for userdata
    luaD_gcIM(&luaO_nilobject);  // GC tag method for nil (signal end of GC)
    luaH_free((Hash *)roottable.next);
    luaF_freeproto((TProtoFunc *)rootproto.next);
    luaF_freeclosure((Closure *)rootcl.next);
    luaS_free(alludata);
    luaS_freeall();
    luaM_free(IMtable);
    luaM_free(refArray);
    luaM_free(Mbuffer);

    LState *tmpState, *state;
    for (state = lua_rootState; state != nullptr;) {
        tmpState = state->next;
        lua_statedeinit(state);
        luaM_free(state);
        state = tmpState;
    }

    Mbuffer = nullptr;
    IMtable = nullptr;
    refArray = nullptr;
    lua_rootState = lua_state = nullptr;

#ifdef LUA_DEBUG
    printf("total de blocos: %ld\n", numblocks);
    printf("total de memoria: %ld\n", totalmem);
#endif
}
示例#2
0
int32 lua_collectgarbage (int32 limit)
{
  int32 recovered = L->nblocks;  /* to subtract nblocks after gc */
  Hash *freetable;
  TaggedString *freestr;
  TProtoFunc *freefunc;
  Closure *freeclos;
  markall();
  invalidaterefs();
  freestr = luaS_collector();
  freetable = (Hash *)listcollect(&(L->roottable));
  freefunc = (TProtoFunc *)listcollect(&(L->rootproto));
  freeclos = (Closure *)listcollect(&(L->rootcl));
  L->GCthreshold *= 4;  /* to avoid GC during GC */
  luaC_hashcallIM(freetable);  /* GC tag methods for tables */
  luaC_strcallIM(freestr);  /* GC tag methods for userdata */
  luaD_gcIM(&luaO_nilobject);  /* GC tag method for nil (signal end of GC) */
  luaH_free(freetable);
  luaS_free(freestr);
  luaF_freeproto(freefunc);
  luaF_freeclosure(freeclos);
  recovered = recovered-L->nblocks;
  L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit;
  return recovered;
}
示例#3
0
文件: lgc.cpp 项目: Akz-/residual
void luaC_hashcallIM(Hash *l) {
	TObject t;
	ttype(&t) = LUA_T_ARRAY;
	for (; l; l = (Hash *)l->head.next) {
		avalue(&t) = l;
		luaD_gcIM(&t);
	}
}
示例#4
0
文件: lgc.cpp 项目: Akz-/residual
void luaC_strcallIM(TaggedString *l) {
	TObject o;
	ttype(&o) = LUA_T_USERDATA;
	for (; l; l=(TaggedString *)l->head.next) {
		if (l->constindex == -1) {  // is userdata?
			tsvalue(&o) = l;
			luaD_gcIM(&o);
		}
	}
}
示例#5
0
void lua_close (void)
{
  TaggedString *alludata = luaS_collectudata();
  L->GCthreshold = MAX_INT;  /* to avoid GC during GC */
  luaC_hashcallIM((Hash *)L->roottable.next);  /* GC t.methods for tables */
  luaC_strcallIM(alludata);  /* GC tag methods for userdata */
  luaD_gcIM(&luaO_nilobject);  /* GC tag method for nil (signal end of GC) */
  luaH_free((Hash *)L->roottable.next);
  luaF_freeproto((TProtoFunc *)L->rootproto.next);
  luaF_freeclosure((Closure *)L->rootcl.next);
  luaS_free(alludata);
  luaS_freeall();
  luaM_free(L->stack.stack);
  luaM_free(L->IMtable);
  luaM_free(L->refArray);
  luaM_free(L->Mbuffer);
  luaM_free(L->Cblocks);
  luaM_free(L);
  L = NULL;
#ifdef DEBUG
  printf("total de blocos: %ld\n", numblocks);
  printf("total de memoria: %ld\n", totalmem);
#endif
}