RBXScriptConnection not increasing on LuauHeap

I ran this code in an empty baseplate:

while task.wait() do
	workspace:WaitForChild("Part").Touched:Connect(function()
		print("touched")
	end)
end

When I checked LuauHeap, the number of RBXScriptConnections doesn’t increase but I’m certain that it’s taking up memory.

When I run this:

local x = {}

while task.wait() do
	local connection = workspace:WaitForChild("Part").Touched:Connect(function()
		print("touched")
	end)
	
	table.insert(x,connection)
end

The number of RBXScriptConnections does increase over time. Does anyone know how I can detect memory increases from the first snippet of code?

1 Like

i’d imagine you have to assign it to a variable otherwise it’ll be completely anonymous and hidden i guess

I guess the only way to keep track of connections is to always reference them?

i guess so. it makes logical sense