问题描述
我有一个很长的飞行程序,它是一个播放器.启动后,它将通过服务器的命令从net加载并运行Lua代码.每个代码都有一个唯一的命名模块.
I have a long time fly program, it is a player. After it started, it will load and run Lua code from net by the server's command. Each code have a unique named module.
每天,它需要加载序列不同的代码(即Lua模块)并运行它们.我担心长时间后内存会溢出...
Every day, it need load serial different code (i.e Lua modules) and run them. I worried the memory will overflow after a long time...
所以,我的问题是:是否可以删除Lua模块?不再使用的模块,我要删除它.
So, my questions is: does a Lua module can be drop? no longer used module I want drop it.
推荐答案
对于用Lua编写的模块,将package.loaded
中的条目设置为nil可能会起作用.但是,这是一个hack,不应该用于任意模块(尤其是C模块)
For modules written in Lua, setting the entry in package.loaded
to nil would probably work. However, it is a hack, and shouldn't be used for arbitrary modules (especially C modules)
来自LuaJIT开发人员Mike Pall:
From Mike Pall, developer of LuaJIT:
对于您的情况,请考虑不使用module
和require
,而是使用诸如loadstring
For your case, consider not using module
and require
, and instead make your own, simpler system that utilizes functions like loadstring
这篇关于如何删除Lua模块的所有代码和内存空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!