Does requiring a module from a cloned object eventually build up to memory problems?

I like to store my UI code inside modules (I like to keep to 1 local/1 server script) structure. And what I do is certain UI gets stored in RepStorage and I clone and destroy it as needed, however I’m starting to fear that could be leading to memory problems.

Code example

local UIClone = UI:Clone()
UIClone.Parent = PlayerGui
require(UIClone.Control)()

And for example inside the Control module inside the cloned UI might be like so

return function()
    local UI = script.Parent

    local Close = UI:WaitForChild("Close")
    
    local function CloseUI()
        UI:Destroy()
    end

    Close.Activated:Connect(CloseUI)
end

However since I’m cloning this module (technically) and requiring the cloned one, then deleting the UI as a whole, that modules code still runs in the background (so if I have loops or connections they continue to run)

How can I work around this problem? :confused:

Just add

while script do wait() end

And add all your disconnects under. There’s better methods but this works fine

Why don’t you just use permanent modulescripts and parent them to ReplicatedStorage?