I have been having major memory leaks recently and I reduced them by disconnecting functions from events I no longer need but I am still having slowly degrading FPS and ping as well as higher memory usage as the game progresses. I read an article which said referencing variables outside of a function cause memory leaks. For example is me referencing the Humanoid variable of a player outside of a function that makes my character use its combat moves causing memory leaks every time a move is used?
For example this is not one of my scripts but I do have a lot of reference to animations and other things in my actual scripts outside of the remote events function itself:
local dance = game.ReplicatedStorage.DanceAnimation
local Humanoid =script.Parent:FindFirstChild("Humanoid")
game.ReplicatedStorage.RemoteEvent.OnserverEvent:Connect(Function()
local track = Humanoid:LoadAnimation(dance)
track:Play()
end)
No, but you should always load animations outside of the function or else itll load the same animation over and over unnecessarily using up memory and itll have a delay because it has to load the animation right before playing it. Edit: This isn’t really a memory leak because it will fix itself once the character is deleted, but itll still cause lag through unnecessarily having tons of animationtracks for the same animation.
Okay. Yes, this is definitely a memory leak. 2000 MB in studio though, that’s normal. I suggest you check ALL loops in your code, also you can look into the console (f9) → memory to see what resources are hogging the most, and if it’s on the server or client.
Ok good news, double checked all of my code and it is fine, I went in game and the memory for client stays at a consistent 930MB and 344MB for server. Sorry did not realise it was different in studio.