Пример #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
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
}