Am I being too cautious with memory leaks? [Solved]

As a newer scripter, I ran into some very bad memory leak issues a month or two ago and do everything I can to prevent them but I feel that maybe I am doing too much. For example here is the start of one the the scripts that allows the character to do a heavy attack :

game.Players.PlayerAdded:Connect(function(Player)

	local PlayerConnections = {
		CharacterConnection = nil,
		DeathConnection = nil
	}
	
	local CharacterConnections = {
		CombatEvent = nil
	}

	PlayerConnections.CharacterConnection = Player.CharacterAdded:Connect(function(character)
     end)
end)

That is not my full code but I basically disconnect everything I can when the player dies or leaves the game. If they leave I disconnect that .CharacterAdded event and if they die I disconnect the CombatEvent within the .CharacterAdded event. Not sure if this is necessary as I have seen a lot of controversy about if a event should be disconnected once the instance it refers to no longer exists.

:Destroy() will disconnect the connections from an instance, so you dont need to worry about disconnecting connections from the player

1 Like

So as long as the instance is destroyed I don’t need to worry? Even if there is a reference to the instance within the event?

If its in the event, you dont need to worry

1 Like

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