PSA: :LoadCharacter() leaks threads! [Memory Leak Bug]

I wanted to post this in #bug-reports , but that channel is locked to “Regulars” only - and the “Regulars” role cannot be obtained.

TL;DR

When running a Loop from within PlayerGui or Backpack then calling :LoadCharacter() you are creating invisible threads that run forever and still affect runtime environment. Killing the Player does not cause this.


:LoadCharacter() is a necessary feature often used by many admin command modules. It’s also a staple standard in games that do not use custom characters and rely on default ROBLOX ones, and many games cannot function without it.

However when using any loop (even if it has a “return” or “break” fallback!) the code runs forever, never stopping, and ramps up significantly. After running a repro test I managed to multiply the code to run up to 73 times a second after a couple of :LoadCharacter() uses - which is less than ideal.
This happens whenever e.g. a “while true do” or “repeat until” loop is used in a Script or LocalScript located in PlayerGui or StarterPack. While LoadCharacter states that

It also clears the player’s Backpack and PlayerGui
(Player | Roblox Creator Documentation)

, it does not actually remove the content, because code is clearly still running, lingering in memory, seemingly parented to itself and continously affecting the environment.

The :LoadCharacter() page has no mention of it possibly causing memory leaks when used with running loops.

Reproduction steps:

  1. Create a loop in any Script
  2. Put the Script in StarterGui/StarterPack
  3. Call :LoadCharacter() from the Server.

The reproduction file clearly shows that while the scripts are apparently cleared, they are still able to produce parts in runtime, and after each LoadCharacter the parts duplicate, and console prints still run.

This is a big problem, because many games rely on :LoadCharacter() for their games to work and many more rely on free provided Admin Commands that make use of :LoadCharacter() to, for example, refresh a player’s Character - thus loading in a second set of loops (that would e.g. check for input updates), slowing down both the Client and the Server.

loadcharacter bug repro.rbxl (29.7 KB)

1 Like

You can message @Bug-Support with the bug information

I am experiencing this too. Did you find a workaround? Destroying() the character then LoadCharacter()?

This isn’t exclusive to LoadCharacter, this is a problem you get when you don’t stop your own threads currently. Try starting a plain while loop in ServerScriptService and then destroy the Script instance, the body will still execute. The bigger issue is threads not respecting Disabled/destroyed state.

2 Likes

is this new? im very confused! this seems like a HUGEEE issue

Here’s an expanded thread about this issue: