I know that you can manually unload modules by doing package.loaded[modname] = nil, but I want to find out if I were to load a module using a local variable, would the module be automatically unloaded?
I created a small test, and the answer appears to be NO. But I would love to hear what others say. I created a Tester.lua module like this:
module(..., package.seeall) print ("RELOADING TESTER"); function test() print ("Tester.test()"); end
Then I wrote the following code to test its loading & unloading:
local function moduleTest() local tester = require("Tester"); tester.test(); end for i = 1, 10 do moduleTest(); end timer.performWithDelay(10000, function () collectgarbage("collect"); moduleTest(); end);
What I found is that “RELOADING TESTER” is only printed once, while “Tester.test()” is printed 11 times as expected.
The reason this question came up is because we use Imagesheets (created by texturepacker) in our code, and these imagesheets have matching data lua files that describe the sheets. And we are trying to figure out whether/how to best unload these data lua files.
Thanks!