Memory Leak Issue

Hello developers and potentially staff,

Long story short, I’m working on a game and after an hour or two, this begins to happen. The memory just slowly goes up until things get a little jumpy in the server and connection becomes more volatile; the server might even crash entirely. I was hoping one of you guys would have a solution to this, such as a way for me to track down exactly what is causing this leak/issue.

https://gyazo.com/cde098b591a4cbc2ff3bbf7c875ef0c4.mp4

1 Like

You’re not providing alot of information for us to work with. A memory leak is generally caused by a script not dumping a variable it is done utilizing. This is one example.

Here are a few questions that can give us more of an idea of what your problem might be, as well as help you.

  • Is the game FilteringEnabled?
  • How many Server Scripts do you have to sort through?
  • Are you using any F R E E M O D E L S?

I’m not personally aware of a tool to check which scripts are leaking memory. Your best bet is to go through all the loops in your game, considering this looks to be a constant climb in memory usage, and find any variables that aren’t being garbage collected properly.

Glad this thread exists, I just checked one of my games and found a memory leak that gets magnitudes worse after 9 hours of a server running.

I’m still trying to figure it out as well, but you can compare these numbers in the table below from a new instance of your game, and a server that’d been live for a while. Check workspace.DistributedGameTime to view how many seconds the server has been live.


3 Likes

I have a series of events that fire fairly frequently and a Stepped function running during a game, but I have no idea which of these (if any) would be causing something like this. I was hoping someone here could point me in a direction so I can investigate and pinpoint where it might be coming from.

But to answer your questions, it is Filtering Enabled, there is only one Server Script (it uses one module fairly infrequently), and there are no free models.

I tried using the collectgarbage() method before, but it didn’t output any higher or lower numbers than normal while the server’s memory was steadily going up.

Edit: I’ll try to provide images soon of what the memory looks like at server start vs a few hours like @TheAmazeman has

It’s never really beneficial to use collectgarbage() manually. It simply forces a garbage collection cycle, which runs periodically regardless.

There really isn’t a shortcut to finding a script or bit of code leaking memory. This is one of the reasons scripters frequently test games to make sure their code is clean. Writing a large chunk and encountering a problem makes it much harder to track it down.

If you don’t feel like going through the code looking for variable declarations and terminations, try commenting out some of the loops, running the game with only one running each time, until you find your culprit by process of elimination.

2 Likes

Alright, I’ll do that.

Otherwise, could this queue exhaustion have something to do with it? And if not, is there a way to clean it up?

Definitely fix that up regardless, you need OnServerEvent in one of your server scripts to detect the PowerAttack event that your clients are firing.

After some testing, I’ve gotten some screenshots of a relatively new server vs an older server (lots of rounds & players), does anyone know what I could look into based on these numbers?

NEW SERVER

OLD SERVER


When the server gets to this point, all interactions and movements become jumpy, connection becomes volatile, and the server may crash.

@TheAmazeman @Kiansjet

I noticed the same behavior with Ultimate Boxing, starting with something like 100-150 and going up to 2,000-4,000 depending on the age of the server. Can’t get any current numbers since it is no longer has multi-hour servers.

Did you ever fix the issue or did you implement shorter server lifetimes to negate it?

Shortening Server lifetime isn’t something I can with the game style.

Are you creating connections to events anywhere that you aren’t properly disconnecting? Over time that can become an issue as far as I’m aware. It’s worth a check.

I’ll check all the connections I make in the game and see if anything is left floating out there, thanks!

Ah so that’s where I learnt that from :thinking:

Does a ton of memory leakage in PlaceMemory > StreamingSounds mean I’m not disposing of sound objects properly?

It just happened from being taken off the featured sort.