First of all, I’m pretty sure some of the memory depends in the Device you’re using, But most of the stuff that can cause Memory leaks is:
-
While loops without a minimal yielding (Still leaks memory even with small yielding)
-
The whole game works only using a Single Script. (Although it can still work with only one script, You would need to optimize it alot) I recommend using the task Library if you haven’t. As it’s currently the best library for Spawning, Waiting and Delaying provided by Roblox.
-
Bad network optimization, BasePart:SetNetworkOwner() can be useful for managing NetworkOwnership of BaseParts.
-
Not disconnecting Connections when you’re not using them anymore, That’s something most people do. They usually create a new Connection (For example,
RunService.RenderStepped:Connect(Callback)
) whenever a certain event happens, But they don’t disconnect it. -
Using
Instance.DescendantAdded
. Yes, You can use it. But running a very “complex” function everytime a new Descendant is added is really expensive. I recommend you doing some checks before running it. -
PhysicsSteppingMethod. Roblox usually always calculates Physics 240 times per second. (Correct me if i’m wrong) But you can change it to “Adaptive” (Via Workspace > Behavior > PhysicsSteppingMethod > Adaptive) which will only calculate Physics at a very high rate only when needed. Whenever it doesn’t needs, It will keep it at 60 times per second by default. It’s really good as it’ll “automatically” manage it for you.
If you want some advice on what you can do, You can use some of the resources below:
- Janitor - For managing Objects, Instances and Connections.
-
Task Library - A way better alternative instead of using
spawn()
anddelay()
. - BufferModule - Great for managing Latency/Lag when using Tools.