View previous topic :: View next topic |
Author |
Message |
Zephiles Advanced Cheater Reputation: 0
Joined: 04 Feb 2016 Posts: 56
|
Posted: Tue Oct 11, 2016 10:39 am Post subject: Memory Leak with Script? |
|
|
In the script I have provided, I am pretty sure that I have some memory leak(s) somewhere.
If I select Yes to run the scripts for dynamic addresses, Cheat Engine will start to use a lot of memory, which seems to continue endlessly. If I select No, then Cheat Engine will not use any additional memory to run the scripts. To go along with this, if I select Yes and then re-run it and select No, then Cheat Engine will still not use any additional memory, but the memory used beforehand will not be returned.
Can someone try to help me with figuring out where the memory leak(s) are?
Description: |
|
Download |
Filename: |
TTYDLuaWIP.lua |
Filesize: |
5.05 KB |
Downloaded: |
320 Time(s) |
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Tue Oct 11, 2016 11:02 am Post subject: |
|
|
Probably the DestroyArray does not work as your expect.
When a Lua table work as an array, it only see from index(or key) 1 to consecutive next integer index that its value is not nil.
So suppose the 1st time you run DestroyArray, the Timers array has 10 items in index 1,2,...10, the 10 items will be destroy and nil.
But in next time, it cannot see an non-nil value at index 1, it will stop enum the array ( ie. #tempExArray = 0 ), since the Timers added at index which is an ever increasing TC counter, so no items in Timers will be destroy and nil after 1st run of DestroyArray.
A quick fix may be instead of enumerate the table as array, enum all its key. ie.
Code: |
for i=1,#tempExArray do --> change to
for i in pairs(tempExArray) do
|
bye~
_________________
- Retarded. |
|
Back to top |
|
|
predprey Master Cheater Reputation: 24
Joined: 08 Oct 2015 Posts: 486
|
Posted: Tue Oct 11, 2016 12:27 pm Post subject: |
|
|
collectgarbage("collect")
force a garbage collection at the end of every OnTimer cycle.
bye~
|
|
Back to top |
|
|
Zephiles Advanced Cheater Reputation: 0
Joined: 04 Feb 2016 Posts: 56
|
Posted: Tue Oct 11, 2016 2:31 pm Post subject: |
|
|
I tried applying both of the solutions provided, and neither seem to be changing anything as far as I can see.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Tue Oct 11, 2016 2:39 pm Post subject: |
|
|
try this before destroying the timers and see if it makes any difference (Setting a method property to nil will explicitly free the function reference)
Code: |
for i=1,#Timers do
Timers[i].OnTimer=nil
end
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
predprey Master Cheater Reputation: 24
Joined: 08 Oct 2015 Posts: 486
|
Posted: Tue Oct 11, 2016 2:52 pm Post subject: |
|
|
Zephiles wrote: | I tried applying both of the solutions provided, and neither seem to be changing anything as far as I can see. |
use this. i tested it, and the memory stays around the same at ~32.9MB. you probably missed out adding collectgarbage() to one of the timer functions.
after clicking yes for the dynamic addressing, CPU usage remained steady at ~2-3%. opening memory browser will cause a spike in my CPU usage of ~7%, opening userdefined symbols will cause another spike of ~7%. thereafter closing the forms will not reduce the CPU load, and destroying the arrays then executing the dynamic addressing script again will cause CPU load to spike to 15% again.
EDIT: problem solved. download removed.
Last edited by predprey on Tue Oct 11, 2016 3:34 pm; edited 2 times in total |
|
Back to top |
|
|
Zephiles Advanced Cheater Reputation: 0
Joined: 04 Feb 2016 Posts: 56
|
Posted: Tue Oct 11, 2016 2:59 pm Post subject: |
|
|
Dark Byte wrote: | try this before destroying the timers and see if it makes any difference (Setting a method property to nil will explicitly free the function reference)
Code: |
for i=1,#Timers do
Timers[i].OnTimer=nil
end
|
|
This also doesn't seem to be changing anything.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Tue Oct 11, 2016 3:01 pm Post subject: |
|
|
I've never bothered looking into it, but timers make Lua allocate a few KB every time they're run. This can end up outpacing Lua's garbage collector.
Example:
Code: | stop = false
local gcT = createTimer()
gcT.Interval = 100
gcT.OnTimer = function()
print(collectgarbage("count"))
gcT.Enabled = not stop
end
local timers = {}
for i=1,20 do
timers[i] = createTimer()
timers[i].Interval = 1
timers[i].OnTimer = function(t) t.Enabled = not stop end
end |
After opening CE, the process's private memory usage was 38.56 MB. After executing that script for 1 minute, private memory usage was at 127.2 MB (logarithmic growth).
To prevent this, make the garbage collector more aggressive:
Code: | collectgarbage("setpause",120)
collectgarbage("setstepmul",400) |
Using the previous example, private memory usage started at 38.3 MB and never got above 40MB.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
Zephiles Advanced Cheater Reputation: 0
Joined: 04 Feb 2016 Posts: 56
|
Posted: Tue Oct 11, 2016 3:08 pm Post subject: |
|
|
ParkourPenguin wrote: | I've never bothered looking into it, but timers make Lua allocate a few KB every time they're run. This can end up outpacing Lua's garbage collector.
Example:
Code: | stop = false
local gcT = createTimer()
gcT.Interval = 100
gcT.OnTimer = function()
print(collectgarbage("count"))
gcT.Enabled = not stop
end
local timers = {}
for i=1,20 do
timers[i] = createTimer()
timers[i].Interval = 1
timers[i].OnTimer = function(t) t.Enabled = not stop end
end |
After opening CE, the process's private memory usage was 38.56 MB. After executing that script for 1 minute, private memory usage was at 127.2 MB (logarithmic growth).
To prevent this, make the garbage collector more aggressive:
Code: | collectgarbage("setpause",120)
collectgarbage("setstepmul",400) |
Using the previous example, private memory usage started at 38.3 MB and never got above 40MB. |
Alright, this worked. Just to clarify, would those same values be applied to my table, or should they be adjusted at all?
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Tue Oct 11, 2016 3:24 pm Post subject: |
|
|
It doesn't really matter as long as memory usage is under control and your script is still running fast enough. The default values are 200/200; adjust them to your liking as specified here.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
Zephiles Advanced Cheater Reputation: 0
Joined: 04 Feb 2016 Posts: 56
|
Posted: Tue Oct 11, 2016 3:32 pm Post subject: |
|
|
ParkourPenguin wrote: | It doesn't really matter as long as memory usage is under control and your script is still running fast enough. The default values are 200/200; adjust them to your liking as specified here. |
OK, thanks for the help!
|
|
Back to top |
|
|
|