加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

lua记忆管理

发布时间:2020-12-15 00:27:08 所属栏目:大数据 来源:网络整理
导读:我如何释放lua堆栈? 解决方法 为什么要这样做? 如果你需要删除Lua栈中的所有元素,你应该调用lua_settop(L,0).引用manual: void lua_settop (lua_State *L,int index); Accepts any acceptable index,or 0,and sets the stack top to this index. If the n
我如何释放lua堆栈?

解决方法

为什么要这样做?

如果你需要删除Lua栈中的所有元素,你应该调用lua_settop(L,0).引用manual:

void lua_settop (lua_State *L,int index);

Accepts any acceptable index,or 0,and sets the stack top to this index. If the new top is larger than the old one,then the new elements are filled with nil. If index is 0,then all stack elements are removed.

这将使堆栈中的所有元素都进行垃圾回收.之后调用lua_gc(LUA_GC_COLLECT)进行垃圾收集.如果您真的需要收集所有可收集的垃圾,请在循环中调用它,直到lua_gc(LUA_GCCOUNT)返回的值保持不变.

请注意,(AFAIK)您不能释放空间,分配给堆栈本身 – 除非您调用lua_close().

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读