#Memory leaks
1 messages · Page 1 of 1 (latest)
Memory leaks are most often caused by recursively calling something without yielding (e.g.
function f()
f()
end )
They will start behaving as loops. This can also occur with logic around them, or even cross modules (e.g. if mod1 requires mod2, and mod2 requires mod1, then that will loop)
Adding multithreading to the mix will just speed it up
A good way to prevent such leaks is by simply trying to avoid such calls, and when you do actually need them, then make sure that there is no way for it to constantly call itself
very cool thanks dude
that is called recursion and is absolutely not a memory leak
you cannot not yield when calling a function
unless you explicitly cast it to a parallel thread, which is stupid in any case
a memory leak on Roblox can happen in many ways but it's most common for people to cause them when they connect to events inside of events or other reused code like functions without disconnecting previous connections
a great example is RunService.PostSimulation:Connect(function()
RunService.PostSimulation:Connect(function()
end)
end)
and I have legitimately seen this bs
and module recursive requires will error regardless
wait so like when i fire an event from client to server, and run some code is some function, i have to disconnect the function?
im not sure i got everything
function module:PlayAnimation(char : Model)
HumanoidAnimTrack:GetMarkerReachedSignal("CamFade"):Connect(function()
--yappatron [...]
end
end
here i'd have to discornnect the get marker reached signal event?
you only disconnect the function when you don't need it anymore
like ever?
usually yeah
eg. if I had some kind of checkpoint trigger that I connect to a part.touched event, then I'd disconnect it afterwards since I don't expect to need it anymore (assuming you can't backtrack)
oh okay i got it