I think my game has a memory leak but I’m not quite sure yet bc while playing it keeps increasing memory
Do you set unnecessary variables to nil? Do you set table keys to nil or clear tables? Do you disconnect events? Do you create instances that never get deleted?
Would like to clarify some things:
- You don’t need to set variables to nil. Anything that is not referenced anymore will properly get garbage collected.
- Yes, it is very important to clear any strong references in tables if that table itself is being referenced. If a table has any Instance key/value but is lost in reference, that table will properly get garbage collected.
- Destroying Instances are important, but for 1 main reason: disconnecting events. Instances that are never parented and are lost in reference will properly get garbage collected.
To be honest it’s good practice to do what I mentioned no matter if it has a small or big effect. I practice what I preach and let me tell you it works wonders. I used to have huge memory leaks mostly because I let my tables grow too big or I had many undisconnected events. I did some research and now I get no memory leaks at all.
In the developer console, click this button named “LuauHeap” from the top-left dropdown menu. After that, make sure to click this button named “Create Snapshot.” It will create a snapshot of the Luau memory usage within your game. You can analyze this over time with multiple snapshots to get an understanding of any potential memory issues you may have. You can do this on both the client-side and the server-side.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
