SoundDispatcher memory leak & fix

Background

The Roblox avatar sound system creates a script in ServerScriptService named SoundDispatcher to replicate sound events between players. Devs can override it by placing their own SoundDispatcher script in ServerScriptService.

The bug

Today we discovered a memory leak in SoundDispatcher.
Briefly, it holds references to Player instances forever without releasing them on player leave, causing Players to never be freed from memory.

The fix

If you have not overridden SoundDispatcher (i.e. most of you), sit tight and we’ll release a fix in the coming weeks. You don’t have to do anything.

If you have overridden SoundDispatcher, you have two options:

  1. Unfork it: Remove your custom SoundDispatcher script from ServerScriptService. This way ensures that you’ll continue to get critical updates to SoundDispatcher moving forward.
  2. Fix your forked copy by applying this patch:
@@ -57,4 +57,5 @@
 	DefaultServerSoundEvent.OnServerEvent:Connect(function() end)
 	AddCharacterLoadedEvent.OnServerEvent:Connect(addCharacterLoaded)
 	RemoveCharacterEvent.OnServerEvent:Connect(removeCharacter)
+	game:GetService("Players").PlayerRemoving:Connect(removeCharacter)
 end
20 Likes

Could this be the reason why my game will sometimes lag and make the sound all distorted?

In the past I’ve also noticed that when I’ve created a sound script - it may use upto 10% script performance - which is why I’ve re-framed creating sound scripts at all.

Game if you’re curious as to the glitchy sound:


(doesn’t happen too often - but sometimes I just get a huge lag spike).

This bug manifests itself as greater memory consumption and degraded performance on the server over time.
You seem to have a different issue.

2 Likes

Ah, my apologies then.

1 Like

This is now fixed.
Enjoy your leak-free sound dispatching.

12 Likes