Stop methods of modules in LocalScripts

How did you watch the output when you left the game?

Server viewer- i tested it in studio

What do you mean by server viewer? Are you trying it in a play solo session and you’re switching to the server? If so, your player is not removed from the game when you do this, you’re just switching to what the server “sees”. You’d be able to see what the client outputs iirc

Would this be necessary because the humanoid.died connection would be in a localscript parented to a tool

Yeah because the character isn’t destroyed when the character dies, just parented to nil afaik, you can try it though by printing connection.Connected

Does this mean connections like uis.inputbegan should also be disconnected? Ive been told connections in tools are automatically disconnected when the tool is destroyed

I had to test it to be 100% certain, but no, your connections won’t be disconnected.


Very lazy testing code inside StarterPlayerScripts (don’t use this unless you want to test to see for yourself):

	print('character was added')
	print('Is old humanoid.Died active:', _G.last and _G.last.Connected)
	print('Is old script destroyed:', not pcall(function()
		_G.lastScript.Parent = workspace


while not script:IsDescendantOf(workspace) do
_G.last = script.Parent.Parent:WaitForChild('Humanoid').Died:Connect(function() end)
_G.lastScript = script

Wtf :man_facepalming::man_facepalming: Im so cooked; my memory leak is probably from my client code connections; then?

If you have them inside tools or in the character and aren’t disconnecting them, then it very well could be, yeah.

1 Like

Ok, perhaps im misunderstanding what happens when a player disconnects, but:

If connections are disconnected when the player instance is destroyed, shouldnt that also apply to tools?

Ive been told that, when a player dies, the tool just becomes unparented. Then, after a given time (if the tool remains unused), Roblox willl gc it, which by extension, will clear connections?

If thats true, then perhaps ur script exists, but maybe in 2 minutes, it wont exist anymore ? Im sorry im just skeptical when theres no documentation or actual input from roblox developers

1 Like

Connections are only “disconnected” when the player is removed from the data model, I don’t really know specifically what happens or how the cleanup is handled on the backend, however once either the player leaves the game (ie they go back to the main menu on mobile/PC app, or when the Roblox process is terminated), is all the memory related to the game itself is freed, there is no lingering memory taken up by the game, because there is no process.

I don’t know if this cleanup process explicitly disconnects the connections, however I do know with 100% certainty that connections created by the client, made in-game cannot be a source of a memory leak after the player leaves the game.

Actually I just tested it now and this does appear to be the case for both tools and UserInputService connections in most cases, so I was wrong in that regard. It’s likely that the majority of your memory leak is coming from somewhere else, if you have one. That being said, about 1/6 of the time, from my testing, the tool does not get garbage collected, so do with that what you will, but I’d suggest disconnecting the connections when you no longer need them to be safe.

@SwedishAeternum just pointed out a very good point; my hitbox visualizer has been on the whole time, which does increase memory gradually :man_facepalming: :man_facepalming:

1 Like

I did some testing for him. Found out the VRAM usage is very high, so it’s a graphical issue. He then realized he had a hitbox visualizer enabled, which was very VRAM resource-heavy.

Using task manager to determine the RAM type btw. Since I already knew the issue was client side.


And I compared the usual RAM usage of my baseplate game which is efficiently programmed. And saw that the GPU memory was abnormally high.

On my game the GPU memory usage maxed out at 0.8/16.2 GB.
And on his, after a single swing, it was already 1.2GB


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