Untracked memory increases overtime

Hello,

So I’ve just noticed that in my game, untracked memory tends to be higher the longer the server’s up time is.
In a server that had been up for around 33 hours, I had ~600MB of server memory where ~200MB was untracked.

Do note that the game was running smooth but it still concerns me as I am a bit of a perfectionist when it comes to memory.

Now I’ve seen a thread where it says that CharacterAdded Event connections are never disconnected automatically, thus the player instance is saved in memory all the time. A solution to this is basically disconnecting the CharacterAdded on PlayerRemoving.

Is it possible that this by itself can generate ~200MB of untracked memory in 33 hours?

1 Like

There could be many different things.

If you have anything containing variables for each player in the connected function than you would want to have a function to wipe all the variables and disconnect the function.

You can disconnect the function but if variables still remain it will take memory.

Another solution is to shut down servers after an amount of time. You would just have to set the max players to 0 and wait for the player count to go down before shutting the server down as to not impact as many players. I’ve seen games do this and it offers more than just memory clears it also means servers with glitches will be removed and old servers will be cycled out for updated servers. Overall if done properly it wouldn’t cause any major issues.

3 Likes

Hmm, I am aware of the variables and Event connections issue and I do set most things to nil or destroy them after I am done using them but I just want to know if it’s possible that the CharacterAdded event connection accumulated that much memory by itself.

1 Like

Its a possibility, if a new connection is made every time the player dies it can add up.

You could try and remove all variables and the connection each time the character dies.

1 Like

As far as I know, a characterAdded event connection is made only once and no new connections are made when the player dies/respawns. One for every player that joins.

1 Like

You could also try using the Find All feature on the Script menu and putting in “:Connect”, so you can easily find all the connections you made in the game, and you might be able to see if something is suspicious or not, if it’s ever cleaned up. Also remember, if the script instance is destroyed (player respawns), or if the instance the connection is made to gets destroyed, the connection is cleaned up automatically.

1 Like

I know. I just don’t know whether it’s possible that the CharacterAdded event connection accumulated 200MB memory in 33 hours by itself. Once again this is because a CharacterAdded event stays active due to the Player never getting destroyed so the it stays connected even after the player leaves.

1 Like

The question is what is being changed as the events are being fired. What are the current features of the game?

1 Like

My game is basically a tycoon. I have several connections such as ChildAdded or Touched (for the buttons) but as far as I know, once the Tycoon is destroyed those connections are all disconnected automatically.

The only thing that I came across that might be causing the untracked memory is the CharacterAdded event which is never disconnected. If your question is what happens in the CharacterAdded, I basically clone a billboardgui to the player’s head.

1 Like

When a character dies it is removed and a new one is added.

The reason for the Player.Added(Plr) before the .CharacterAdded(Char) is only so that you can connect the character added to every player.

If you have other events make sure they are all disconnected and wiped.

Are there anything that controls the overall global variables or something else that progressively changes over time?

While you’re at it, there are plenty of topics covering this issue, the latter being the most probable solution:

3 Likes

Another thing that just came in mind while reading the second thread you’ve sent is that since I am constantly spawning a lot of parts within the tycoons and removing them, they’re never fully “removed” a part of the data is still saved into memory apparently (Source below). Still, I can’t do much about that.

Source:

I suspect you have scripts attached to the tycoon directly rather than indirectly from the ServerScriptStorage. I’m not entirely accurate on it, but might as well be a longshot.

No I have a module script which handles all tycoons.

We are not perfectly certain about what is generating the amount of untracked memory. There is little to no other solutions than securing the connections properly.

Back in RDC 2020, they introduced 5 different powerful code patterns that are useful. One of the reason being successful memory management.

Currently, it’s not really a problem. The game still runs smoothly and most likely will continue to do so. However, I do wonder what would happen in a much bigger game and how they manage to handle this problem.

It is their memory management in code that avoids this issue. However, we should not be concerned about the untracked memory until your playerbase responds with concerns about lag on their devices.

1 Like