Memory usage in Script performance tab

I’d really like the script performance tab to show individual script memory usage if possible, since I constantly run into the notorious “not enough memory” -error but I have over 200 modules/scripts so It’s practically impossible to find the root cause of it.

(no it’s not my hardware I have 16 gigabytes of memory, 3 gigabytes of video memory)

4 Likes

You should check your code for recursive functions, storing lots of data, …
One does not simply run out of memory in roblox

1 Like

but I have over 200 modules/scripts :frowning:

It’s gonna take me weeks to find out the reason

Do all of them start using a lot of memory at startup?
In that case I could write a quick script that finds the memory eater.

1 Like

@Elmuowo
Since you liked, I assume they do:

local scripts = {}
local function rec(o)
	for k,v in pairs(o:GetChildren()) do
		if v.ClassName == "Script" then
			table.insert(scripts,v)
			v.Disabled = true
		end rec(v)
	end
end rec(workspace)
rec(game:GetService("ServerScriptService"))
local start = gcinfo()
for k,v in pairs(scripts) do
	v.Disabled = false wait(1)
	local dif = gcinfo()-start
	func = dif > 1000 and warn or print
	func(v:GetFullName(),"=",dif)
	start = gcinfo()
end print("We're done, folks!")

Of course untested, but it should work (in theory).
Just do Start Server (or even online) and run the code.
(If you do it online, you should probably use F9)
(If you do it in a script, big chance it disables itself)

3 Likes

Well I’m running out of memory on the client, and I tried to put that as a localscript and set rec(game.Players.LocalPlayer.PlayerGui) since thats where my client code resides, but it prints “Were done here folks” as soon as it loads up, and If I try to put that in the command bar after memory has run out I cant because roblox has crashed

Did you change the “Script” to “LocalScript” in the code?

oops lemme do this again

18:55:50.407 - startScript re-entrancy has exceeded 3
18:55:50.407 - Script ‘Players.Player1.PlayerGui.Diagnostics’, Line 13
18:55:50.408 - Stack End

Your code

Alright it apparently still ran

18:55:51.311 - Players.Player1.PlayerGui.Diagnostics = 1098
18:55:51.312 - Players.Player1.PlayerGui.Diagnostics = 1097
18:55:51.312 - Players.Player1.PlayerGui.Diagnostics = 1104

That’s probably because the code disabled and enabled itself…
Just add an extra check:

		if v.ClassName == "Script" and v ~= script then
			table.insert(scripts,v)
			v.Disabled = true
		end rec(v)

EDIT:

Uh, all on the same second? Did wait(1) bug out?

EDIT2: Nvm it prints 3x statistics about itself, as it disabled and re-enabled itself.
Add that check I posted a few lines back, or put Diagnostics in Backpack.
(In case you don’t do rec(Backpack), that is)

I added the check and now theres no output but “were done here” initially

Uh, mind posting a screenshot of your Explorer, including the location of the Diagnostics script?


local scripts = {}
local function rec(o)
	for k,v in pairs(o:GetChildren()) do
		if v.ClassName == "LocalScript" and v ~= script then
			table.insert(scripts,v)
			v.Disabled = true
		end rec(v)
	end
end rec(script.Parent)
local start = gcinfo()
for k,v in pairs(scripts) do
	v.Disabled = false wait(1)
	local dif = gcinfo()-start
	func = dif > 1000 and warn or print
	func(v:GetFullName(),"=",dif)
	start = gcinfo()
end print("We're done, folks!")


That should work…

In that printthing it means scripts is empty.
That means rec(startergui) didn’t add any localscripts…
it definitly should add some…

On the other hand, your first memory error happens in TransparencyController… maybe that script’s the cause?

EDIT: Maybe do wait(1) before calling rec()
It could be replication lag…

1 Like

Players.Player1.PlayerGui.Goggles = -344
Players.Player1.PlayerGui.Animate = -55
Players.Player1.PlayerGui.Movement = 60
Players.Player1.PlayerGui.Dev.DevStats = 27
Players.Player1.PlayerGui.RbxDev.MembershipCheck = 31
Players.Player1.PlayerGui.BloodGui.LocalScript = 17
Players.Player1.PlayerGui.Blood = 14
Players.Player1.PlayerGui.ClientMain = 57
Players.Player1.PlayerGui.DoorTestScript = -63
We’re done, folks!

Also TransparencyController is a StarterPlayerScript(by Roblox) and I don’t believe I even use that behaviour in StarterPlayer, I believe it’s just the first script to realize there’s not enough memory

Well, reviewing those results, it doesn’t happen soon after the scripts run.
Only thing that you can do is enable them 5 by 5 or so.
If memory still runs out, then check the left over 5 one by one.

Run some code in the command bar that crawls through the source code of all of the scripts/modules/etc, and use complexity analysis to find bits of code that are executed really often and multiply by the number of variables created in each block. Then print those out, sorted by how many variables are created, and you’ll find your memory problem.

This is getting way out of hand, why can’t there just be a memory usage counter per-script in the Script Performance Tab.

I might have to rewrite my entire code base again here (35000 lines but most of that is modules)

There should be an indicator of memory usage in Script Performance, but I assume you want to find the problem now. Unless you want to wait a couple months or longer for memory statistics in Script Performance, you have to find out which of these modules is causing the problem and the best way to do that is automatically.

2 Likes

We can assume it’s probably caused by something that runs (close to) every tick, like RenderStepped.
We also know memory shouldn’t be an issue unless you’re storing data and never clearing it.