Tried to fix the memory leaks by setting all unneeded values to nil but it doesn’t seem to have worked.
It’s risen from around 270 to 290 in 10 or so minutes.
From my experience, not disconnected events can cause a lot of memory leaks, make sure to double check that you disconnect events that aren’t needed. You can use modules like Maid or Janitor to help with garbage collection
All connections that aren’t needed are either destroyed (in the case of TweenService) or are used all the time. (Remotes and other things such as RunService)
Other than what other people before me have suggested, there is not a lot you could do other than optimizing your already existing scripts to use less resources.
You usually shouldn’t use table.clear, table.clear is for when you are going to reuse that table.
table.clear removes the things inside, but doesn’t free the memory allocated for that table, so if that is never used, it causes what is essentially a memory leak.
When it comes to instances, your best bet is to always destroy what is not used. The main issue with Instances is that they don’t deal with self-references (I forgot the word, let’s go with that) properly.
This is a popular example:
local BindableEvent = Instance.new("BindableEvent")
BindableEvent.Event:Connect(function()
(Bindable.Event) --> this causes a memory leak forever, IIRC
end)
A lot of things, like Tweens, are weirdly instances, so your best bet is to deal with them automatically, always properly destroy them and remove their references. I used to have QuickTween which is just a wrapper for creating Tweens that automatically deals with destroying things after a tween is finished as I wouldn’t use it anymore anyways in any occasion.
If you’re not already, but I think everyone is by now, use a Lua implementation of Signal, don’t use BindableEvents.
Yeah, you’re right about table.clear. I kind of assumed it was within another table, and for some reason (force of habit) I always clear a table before I then assign the variable that holds it to nil. Thanks for the clarification.