Skip to content

Memory leak with TriggerClientEvent #3114

@niCe86

Description

@niCe86

What happened?

When sending tables through TriggerClientEvent, memory is leaking. It is probably more noticeable with larger tables.

I'm using TriggerClientEvent a lot and my server RAM usage gradually increases from 500 MB to up to 10-15 GB at the end of the day (FXServer is being restarted daily).

Expected result

When sending table through TriggerClientEvent, allocated memory should be cleared.

Reproduction steps

collectgarbage('stop')
print(1, collectgarbage('count'))

local data = {}
for i = 1, 100000 do
data[i] = i
end

print(2, collectgarbage('count'))

for i = 1, 100 do
TriggerClientEvent("Test", playerid, data)
end

print(3, collectgarbage('count'))

data = nil
collectgarbage('collect')

print(4, collectgarbage('count'))

Importancy

Unknown

Area(s)

FXServer

Specific version(s)

Tested on FiveM artifact 12180 and 12651
I have confirmation from @IS4Code that on some ancient artifact from 2022 this doesn't occur

Additional information

The garbage collect clears all the garbage, but RAM usage won't decrease.

Example of my results:
[ script:wtls] 1 354979.76171875
[ script:wtls] 2 359075.85546875
[ script:wtls] 3 395079.3125
[ script:wtls] 4 350609.63769531

Example of actual RAM usage:

  • 560 MB RAM at the beginning
  • 629 MB RAM after execution of the code above
  • 580 MB RAM after few seconds and another manual garbage collect (just to be sure)
  • 568 MB RAM after resource restart

You can easily repeat the test script and the RAM will gradually increase. I have suspicion, that this memory leak might somehow degrade CPU performance as well?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriageNeeds a preliminary assessment to determine the urgency and required action

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions