This has been our most problematic issue since releasing our game 99 Fail. We’ve narrowed down our source of server-sided memory leaks to almost solely the respawning of characters. This is particularly problematic for our game due to players constantly dying within servers as large as 80 players:
A typical server will crash (due to memory exhaustion) after only a few hours, and this was even worse before we switched from R15 to R6. We vigilantly track and cleanup memory via Janitors and have even resorted to now manually destroying the Character and Player instances ourselves.
Our game has streaming enabled with a 2 second respawn time. The vast majority of player respawns occur from their humanoids health being set to 0. We do call :loadCharacter but only rarely if streaming enabled causes them to fall past the kill parts.
Thanks for posting this engine report. We are confident this isn’t solely an issue with our game and would love to have it resolved, especially with David’s goal of empowering large 1000+ player servers.
Isn’t the memory leak being caused by how Roblox handles death? I literally had a leak in my game not long ago because the Characters don’t get destroyed on death and all the connections I had on it were staying on the server (servers crashed), they just get parented to nil. Not sure, if objects like the character parented to nil will get Garbage Collected on the client.
I spawned and reset my character 2 times, not even kicking the player out destroyed them:
I’ve been dealing with this issue for a while now, and it seems like it had something to do with PlayerGui replication, because when I made a custom script to load StarterGui contents into the PlayerGui through the client instead of the server, the memory going up every time a character died completely stopped. I still don’t know what caused this since the way I’m doing it now is not a real solution and kind of a hack.
The memory difference between Studio and Player is completely valid, when you run the game in Studio, you are running the server on your machine. The best way to test anything memory related is by Player. + Studio is more intensive to run than Player.
No wonder why my custom death screen I was coding was causing memory leaks. I’m pretty sure it’s LoadCharacter because of the fact the humanoid doesn’t get killed, because my game instead detects when a player value called Death is set to true to cause a custom death system to play which uses LoadCharacter.
Thanks for reporting this bug, hopefully Roblox fixes this as soon as possible!
I’ve suspected this happening to both of my games (both Combat-RP games with players constantly resetting) for some time now but I have denied even after refactoring my code to account for memory leaks. Thank you for confirming this was indeed a thing. I’ll likely be changing the way my players “die” to bypass this for now.
I can confirm that this is caused by player:LoadCharacter(). I created a test place where it spam loads your character in a loop, and the memory only goes up. Went from 300 to 600 in only a few minutes, it doesn’t appear to have a limit.
I have noticed that spamming :LoadCharacter does indeed crash servers. Having remotes that respawn the local player don’t seem to be an issue, but if the loop happens on the server without that network delay, I’ve seen it to become problematic. Not sure if this has anything to do with memory or just connections being spammed, but servers do eventually crash on LoadCharacter loops.
I noticed this behavior in one of my private games when I changed characters often (by using LoadCharacter), and because of this I rescripted snippets of code and removed unnecessary connections to see if it would make a difference, although the memory usage kept permanently increasing. I’m glad this has finally been addressed as it’s a major issue.
Is this related to humanoid / characters in general, or specifically only default characters spawned from LoadCharacter or the default respawn flow? Wondering if I will see an improvement in memory usage in my game about custom characters wherein I set player.Character directly.
The leak is only somewhat coincidentally related to avatar respawn. The bug was actually in one of our core Lua libraries we use for the core UI (in-experience menu, topbar, playerlist, etc.). It leaked a lot of memory on respawn due to one of our menus in the core script performing tear down and then setup again every respawn (a separate problem). This wouldn’t affect all games depending on how the custom characters are implemented. All games will probably see some memory improvement though.
It appears that respawning other people’s characters also leaks memory. (I can sit passively in many games and watch memory increase, unlikely caused by our code, but who knows).
Does this fix cover that scenario? Or should I submit a reproduction for better fixes?