Skip to content

Commit 99bcfeb

Browse files
authored
Fix memory leak of player reference caused by logs (#2017)
* Fix memory leak of player reference caused by logs * Fix typo
1 parent f89ea7a commit 99bcfeb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

MainModule/Server/Core/Logs.luau

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ return function(Vargs, GetEnv)
8888
log.Time = os.time()
8989
end
9090

91+
if log.Player and type(log.Player) ~= "table" then
92+
local id = log.Player.UserId
93+
local pData = Core.PlayerData[tostring(id)]
94+
local userInfo = pData.userInfo
95+
96+
if not userInfo then -- Cache table allocation for player userInfo table to save on memory
97+
userInfo = {
98+
Name = log.Player.Name;
99+
UserId = id;
100+
}
101+
pData.userInfo = userInfo
102+
end
103+
104+
log.Player = userInfo
105+
end
106+
91107
if tab then
92108
if tab.__meta == "DLL" then
93109
tab:AddToStartAndRemoveEndIfEnd(log, Logs.MaxLogs)
@@ -153,7 +169,7 @@ return function(Vargs, GetEnv)
153169
local newTab = if isTable then table.clone(log) else log
154170

155171
if (isTable and not log.NoSave) or not isTable then
156-
if isTable and log.Player then
172+
if isTable and log.Player and type(log.Player) ~= "table" then
157173
local p = log.Player
158174
log.Player = {
159175
Name = p.Name;

0 commit comments

Comments
 (0)