lua 垃圾回收
垃圾回收
lua 自动进行垃圾收集,可不用手动操作
collectgarbage(opt, arg) :垃圾收集,arg可选
This function is a generic interface to the garbage collector. It performs
different functions according to its first argument, opt:
* 该函数用于垃圾收集,第一个参数可控制垃圾回收动作
# collect:做一次完整的垃圾收集循环,默认
Performs a full garbage-collection cycle. This is the default option.
# stop:停止垃圾收集器的运行,直到显示开启垃收集器
Stops automatic execution of the garbage collector. The collector
will run only when explicitly invoked, until a call to restart it.
# restart:重新开启垃圾回收器,使其自动运行
Restarts automatic execution of the garbage collector.
# count:以K(kb)为单位返回 Lua 使用的总内存数
Returns the total memory in use by Lua in Kbytes. The value has a
fractional part, so that it multiplied by 1024 gives the exact
number of bytes in use by Lua.
# step:单步运行垃圾收集器,步长由arg控制
Performs a garbage-collection step

本文介绍了Lua的垃圾回收机制,包括自动进行的垃圾收集、collectgarbage函数的使用及其不同参数的功能,如collect、stop、restart等。还详细解析了增量模式和分代模式的垃圾回收,并给出了相关参数的解释及示例。通过对内存使用量的控制,调整垃圾回收的频率和时机,以优化程序性能。
最低0.47元/天 解锁文章
944

被折叠的 条评论
为什么被折叠?



