High Memory Usage

Hi, so right now our game, Hide and Seek Shooting, when the servers get old, the memory starts to rise up. The Core Memory was 1175 MB, with the Core Memory being 898 MB. In the Core Memory, default is 422 MB and physics/step is 171 MB. So my question is what could be potential reasons could result in high Core memory. Is it memory leaks in my scripts? I’m not sure, but I think memory leaks only have an increase in the Place Memory’s Lua Heap? Thanks for any help provided!

You could be using _G or shared too much, too many unused or initialized variables in the stack or heap. You could be calling too many functions or relying too heavily on loops, and the list goes on.

I don’t know what your problem is because I don see any code or problems in the question.

1 Like

Thanks for the reply, I’ll be checking my scripts. And also, I some questions. First, does relying on RunService.Heartbeat for the round countdown clock add to the memory stack? Also, does shared variables means variables that are declared without adding local in front of it, and if so, how much more memory does it use than local variables? Lastly, in my main script, it has about 2000 lines which has an endless loop for the rounds in the game, which calls functions along the way as part of the round, but doesn’t the functions get GCed after exiting the function? What I mean is that why does the Core Memory accumulate? I would really appreciate any help provided. Thank you!

No, variables of which defined without a local are global to the scripting environment/script. Local is a access modifier, if you put local in a variable then it will be local to the stack, like inside a function or a condition.

shared and _G are keywords for global variables that can be accessed to any extent on any scripting environment or stack. Which I am relatively certain it is stored on the heap. Because in theory all data that is put into the heap can be accessed and modified anywhere by the programmer.

Your problem is most likely that you are not clearing up unused items.

I really appreciate your help here. Just a few hours ago I had a breakthrough, but after trying to change up the code, it isn’t working. So I realized the problem with my Core Memory’s default and physics/step going so high was because of unanchoring. In our game, there’s some custom made NPC statues that explode into pieces when dealt a certain amount of damage, and each time the damage threshold is met, some of the pieces unanchors and a BodyVelocity is inserted into the part to make it fly. But even after the part is destroyed, the memory doesn’t drop back down. I removed the BodyVelocity portion of the code, leaving with just the unanchoring portion, but the memory still increases. So might you have a solution to this by coding? Or is this a Roblox engine bug?

If your memory continues to increase, you’re probably not cleaning up event listeners correctly. Event listeners are the leading cause of memory leaks, since they will prevent garbage collection on anything their defined within, including tables that are no longer in the scope, until they are disconnected.

If this ends up being the case, I’d recommend checking out Quenty’s Maid, which is designed for this exact purpose

1 Like

Nevermind, I just realized that even know the default and physics/step memory increased, the Untracked memory also decreased at the same time, neutralizing the memory level, and the game server stopped freezing up. So I guess the issue was fixed. Thanks guys!

Edit: If anyone was seeing this post, the problem that was causing the memory leak was me not destroying the model even though all the parts inside the model have been destroyed. It looks like a model even without any parts could take up a decent amount of memory.