Can the same function be duplicated multiple times creating a memory leak?

For each iteration on here, will there be a newly created OnTouch function specific to that argument?

Read code from bottom → top

-- Connections(v) gets called 24x
  -- because model has 24 children parts
local function connections(v)

    -- OnTouch(hit) declared 24x
    -- OnTouch(hit) <- created 24x?
   -- because we iterated 24x?
   -- or does it only get created once?
    local function OnTouch(hit)


local Model = workspace.Model:GetChildren()
print(#Model) -> 24 -- 24 children parts

-- Loops 24x because Model has 24 children parts
for _,v in pairs(Model) do
    connections(v) -- finally gets ran
    ... <--  etc codes..

To my knowledge, the function and event will not be garbage collected, but as long as you’re running it a small and finite number of times it shouldnt cause a memory leak

Im not lua garbage collection expert too, so Im sure someone whos more experienced in this matter could correct me if Im wrong

I kinda need a little bit more clarification so here’s another example

for i = 1, 24, 1 do

        local function foo()

        while true do end

will function foo() be created 24x and permanently stay in the memory?

I believe so, neglecting the fact that that code would make roblox implode because of the while true do end

Yeah, I forgot the loop doesn’t have a wait() in it so don’t mind that.