View Issue Details

IDProjectCategoryView StatusLast Update
0009480Multi Theft Auto : San AndreasScriptingpublic2018-10-12 15:20
ReporterMaitoPurkkiAssigned Toccw 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionsuspended 
Product Version1.5.3 
Target VersionFixed in Version 
Summary0009480: Memory leak when using Vector3
Description

Creating lots of Vector3 objects causes the resource's memory usage to grow even if the Vector3 objects are no longer in use. This causes problems if you're using vectors in onClientRender functions as memory usage can grow very quickly.

Example code:
function test()
for i = 1, 1000 do
local a = Vector3(0,0,0)
end
end
addEventHandler("onClientRender", root, test)

Performancebrowser reports memory usage of well over 100 Mb after running this script for a couple of minutes.

Replacing Vector3(0,0,0) with {0,0,0} in my example keeps memory usage under 1 Mb, but using vectors is much more convenient than using tables.

TagsNo tags attached.

Relationships

has duplicate 0009515 closed New issues OOP usage creates memory leaks 

Activities

extz[c]

2016-12-21 00:58

viewer   ~~0025521

Had to rewrite my script due to this bug, Can someone look what's happening here?

arranTuna

2016-12-21 12:11

manager   ~~0025525

Is there a way to manually destroy these kind of things like a:destroy? Could help until the memory leak is fixed.

Kenix

2016-12-21 12:39

updater   ~~0025526

Last edited: 2016-12-21 12:39

View 3 revisions

You can use Lua classes (via setmetatable). Create your own vector3 class.

ccw

2016-12-31 10:42

administrator   ~~0025596

Try: collectgarbage('collect')

MaitoPurkki

2016-12-31 19:09

viewer   ~~0025597

Calling collectgarbage('collect') in onClientRender seems to fix this issue. Would be nice to have this happen automatically though.

ccw

2016-12-31 20:27

administrator   ~~0025598

Try this once:
collectgarbage("setpause",100)

AfterAll14

2017-01-04 01:20

viewer   ~~0025602

ccw, seriously! You should announce fixes like this on the main forum page with large bold letters.
I was just about to spend lots of time trying to fix it in mta source, seems like there may be even nothing to fix.
But yeah, adding "collectgarbage("setpause",100)" once inside script seems to fix the problem.
Though it works in some weird way, and probably something still leaks out there, but those leaks seem to be reasonably low (well, not going to kill my laptop in about an hour at least xD).

myonlake

2018-09-05 02:31

updater   ~~0026925

Is this still confirmed and is there no way to fix if it is?

qaisjp

2018-09-05 06:22

administrator   ~~0026937

Moved to https://github.com/multitheftauto/mtasa-blue/issues/321

I have added the tip to https://wiki.multitheftauto.com/wiki/Vector

ccw

2018-10-12 15:20

administrator   ~~0027098

Fixed in https://github.com/multitheftauto/mtasa-blue/commit/6f3fe6d827b8eed34db7bd06a796849731abbbfb

Issue History

Date Modified Username Field Change