Would this module get removed from the memory?

Say you have a module script like this:

local module = {}

local connection

function something()
	-- do stuff here
end

function module.start()
	connection = game:GetService("RunService").RenderStepped:Connect(something)
end

function module.stop()
	connection:Disconnect()
end

return module

If a local script does this:

local module = require(path to module script)

module.start()

task.wait(3)

module.stop()
module = nil

Does that required module not exist anymore? Or will it still exist in the memory?

1 Like

No, it would not exist since it is changed to nil, also so the variable is collected by the garbage collector.

Clear part reference so it gets picked up by the garbage collector
https://developer.roblox.com/en-us/articles/Nil

1 Like

It will no longer be referable/accessible to the local script but the ModuleScript itself will still exist including for other scripts which have required it.

2 Likes