[Closed] Help with a memory leak

I have a memory leak in my game. I have separate experiences for the public / live version and the development place. In the live place, there appears to be no major memory leak, while in the development place the memory rises by a considerable amount in a fairly short timeframe.
(ctrl + f7 used to check memory usage)

How do I find out what is the source of the memory leak, for example what are the common mistakes or practices that cause it?
And how do I prevent my code from causing this, how do I ensure garbage collection handles data?

One thing to note is there is several hundred MB of untracked memory, however I don’t know how to ensure that unused data is garbage collected, nor where all this data is even coming from.

make sure you break all your loops when they are not being used
if you are creating parts or instances through script make sure to destroy them if they are not being used

set variables to nil if they are not being used

1 Like

Use StreamingEnabled if you can (for the workspace), disconnect unused connections, try to minimise the amount of connections you use.

Just adding to @MikeartsRBLX suggestion about instances, I would also like to point out that tweens are instances. You should destroy them as well, but try and reuse them if you can.

i’m pretty sure everything is an instance (folders, variables, parts, tweens, values, attributes, etc.)

Attributes aren’t and variables aren’t, but yes the rest you listed are. Tweens in particular are not created by Instance.new, rather TweenService:Create so they may not seem like instances although they are.

soo it turns out the memory leak was not in-fact caused by my code but rather a fault with the system I used. I had updated my game from an older version to a newer version in the development place, and it seems the memory leak just went unnoticed entirely for 3 years.

I appreciate the help regardless!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.