Should I worry about GetPropertyChangedSignal() taking up memory?

Hey you all. I’m currently making a data saving system and I need it to be updated whenever the player’s leaderboard value changes.

It works, but I’m not sure if I should worry about the server eventually shutting down from taken up memory, since when a player is added, 2 different GetPropertyChangedSignal() methods are used.
I couldn’t find anything specific about this anywhere.

So the main question is:
If the player leaves, does the property signal stop, or do I have to stop it in order to save memory?

(Uses Profile Service)

Here is the code if you need it:

cash:GetPropertyChangedSignal("Value"):Connect(function()

    --Update Data

end)

wins:GetPropertyChangedSignal("Value"):Connect(function()

	--Update Data

end)

Most value objects overwrite the .Changed event, so that it only listens to the Value property.

When this is the case, these codes will accomplish the same.

IntValue:GetPropertyChangedSignal("Value"):Connect(function()
	print(IntValue.Value)
end)

IntValue.Changed:Connect(function(Value)
	print(Value)
end)

This is significant, as the first connected function contains a reference to the signal’s associated instance in its closure. If the player is not destroyed (which would disconnect all signal connections from its descendants), this cycle of references will keep the value object (and by consequence its connections) from being picked up by garbage collection.

The second approach solves this problem, as it avoids the need to reference the signal’s associated instance, by instead being fed the changed value directly.

1 Like

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