I currently have a function in a module (down below). This function is flagged inside the “Unique References” section of the LuauHeap menu, meaning some sort of memory leak is happening here as it is not being garbage collected. The line given is line 1
below, and it stated it was an “upvalue” type. How can I fix this upvalue related memory leak?
I have other functions relating to this same memory leak in the same script, but this one is the most basic one so I’m sending this one. They all relate to some sort of event connection though. Since its an event connection, it seems less simple.
function Module:InitTrunk(Player, Car)
local TrunkPart
for _, Obj in Car.Body:GetChildren() do
if Obj:IsA("BasePart") and Obj.Name == "Trunk" then
TrunkPart = Obj
break
end
end
if not TrunkPart then return end
TrunkPart.Transparency = 1
local Prompt = CreatePrompt.new({
HoldDuration = 0,
Name = "TrunkPrompt",
MaxActivationDistance = 7,
ActionText = "Open",
ObjectText = TrunkPart:HasTag("Frunk") and "Frunk" or "Trunk",
Parent = TrunkPart,
Player = Player.Name
})
Prompt.Triggered:Connect(function(Plr)
if Plr ~= Player then return end
if Plr.Team == game.Teams.CIVILIAN then
GUIEvent:FireClient(Player, "CivTrunk", TrunkPart:HasTag("Frunk") and "Frunk" or "Trunk")
else
GUIEvent:FireClient(Player, "Trunk", TrunkPart:HasTag("Frunk") and "Frunk" or "Trunk")
end
end)
return Prompt
end
Anyone have any thoughts on how I can fix this?