Does requiring module inside function creates memory leaks?

  1. What do you want to achieve? Wanna save some memory

  2. What is the issue? Well i have function inside of my code that requires module and i am wondering if that will create or leave memory behind? even i called it repeatedly?

  3. What solutions have you tried so far? Didn’t found one

function SpawnObject(Player,ObjectName, Parent)
	if not ObjectName and not References.Paths.BurgerPlaceFolderServer.Objects:FindFirstChild(ObjectName) or Player.Team ~= References.Services.Teams["Burger place worker"] then return end
	local Object = References.Paths.BurgerPlaceFolderServer.Objects:FindFirstChild(ObjectName):Clone()
	Object.Parent = References.Paths.Objects.FoodObjects
	Object.CFrame = Parent.CFrame
	require(References.Modules.Dragging).SetupPart(Player,Object) -- this
1 Like

It will not leak memory unless the module itself creates a memory leak, such as a connection in SetupPart.

During the initial call, require loads the module, runs the code it the body, and caches what it returns; any subsequent calls return the same module.

Repeated require works just fine, but requiring it once at the top of the script is usually better and a bit more efficient.

1 Like

Thank you, Now i can sleep at night :slight_smile:,

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.