I'm confused about 'memory leaks'

Okay, let me describe a specific scenario so I can ask this correctly.

In a blank baseplate studio instance, there is a single script is within ServerScriptService, and it’s contents are the following:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

	end)
end)

In the scenario of a running server of five players within the studio instance described above, one player leaves the game and four remain. As per the script states above they would all have CharacterAdded connected to their player whenever they join, but when that one player leaves, is that player’s CharacterAdded function still connected to their player even though its nil? If it is, is that what a memory leak is?

1 Like

No, not in this certain scenario. As when the player leaves, its connection is destroyed thus no memory leak is created.

3 Likes

Memory leaks are frequently mentioned in memory management.

References in a script should be considered to be controlled, because the more references that becomes ‘hanging’ in the code, the less free memory there are due to their operations occupying the memory for no real purpose.

Don’t worry about the player.CharacterAdded connection, it is GC’d(garbage collected) when the player instance has left; been destroyed.

1 Like