Code that previously properly cleaned up after itself may no longer do so, I’ve tested many times with different pieces of code and usually they may not properly garbage collect.
The 1st Repro is the easiest to reproduce and will always memory leak, regardless of the table size, deleting the script that created the table, de-referencing the table, waiting before deleting the script that referenced the table, and so on. The place is a default base-plate with nothing intensive that runs, even the default chat is disabled, and even has player character appearance turned off.
1st Repro Game: Memory Leaker Tester - Roblox (Uncopylocked, you can edit it in Roblox Studio)
1st Repro Code: (Acts the same in non-Parallel as well, won’t garbage collect the table, I’ve also tested having a smaller table and having a larger table the size of the table doesn’t matter and will never garbage collect even if the table will end up crashing the player)
1st Repro Picture: (I even waited 15 minutes after clearing the table & deleting the script for it to potentially garbage collect the 2 GBs of memory usage from the table)
(Client-Side)
(Server-Side)
(Server-Side memory usage)
2nd Repro Code: (Not the same as above, this code should almost always garbage collect)
local Table: {string} = {"Testing GC"}
local GCCheck = setmetatable({Table}, {__mode = "kv"})
Table = nil
task.wait(10)
print(GCCheck[1])
2nd Repro Picture:
For some reason, in Roblox Studio the 2nd repro will randomly either garbage collect or not, it seems to be a random chance for the table to garbage collect, however, the 1st repro will always memory leak regardless of play testing in Roblox Studio or joining the game in the Roblox Player.
I haven’t tested any other forms of memory leaking that doesn’t include tables so I’m unsure if other things that should be garbage collecting aren’t being done. This hasn’t always been the case as tables use to properly garbage collect always, I’m unsure of when this first started happening though so I presume that someone changed how the garbage collector works.
System Information: (Shouldn’t be necessary as I’ve had multiple players join the 1st repro game and have it happen to them as well)
Windows 11, Intel i9-13900KF, 64GBs DDR5, NVIDIA 4090
Expected behavior
The tables in both example should always clear the table and garbage collect it, especially if the table is using up to 2 GBs of memory usage and holds zero references and the script it originates from was deleted after clearing the table and its references. In actual games there’s a few cases where this memory leak is happening as it’s how I found out about it. (Of course the actual game wasn’t using a 2GB table but after awhile it starts to add up from never garbage collecting)