Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to deal with while loops/timers eating up memory?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Wed Feb 08, 2017 6:36 pm    Post subject: How to deal with while loops/timers eating up memory? Reply with quote

I never really paid attention to it before but looking at task manager I noticed how much my trainer climbs in memory usage over time, after seeing this thread: http://forum.cheatengine.org/viewtopic.php?p=5694918 , I applied Parkours solution and it helped a bit, but is it inefficient to even be using so many timers or any while loops?
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Wed Feb 08, 2017 6:51 pm    Post subject: Reply with quote

You'd have to post your code in order for us to see what you're doing wrong.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Wed Feb 08, 2017 6:54 pm    Post subject: Reply with quote

Are you calling create* functions frequently ? If so, make sure you destroy() them when you don't need them anymore
_________________
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
View user's profile Send private message MSN Messenger
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Wed Feb 08, 2017 7:22 pm    Post subject: Reply with quote

@DB I use the form designer to create timers since I need them while the game is running

@Zanzer it's not really a specific issue with my current code but more in general when using over a few at once, was just wondering if there's any additional methods I could apply for less mem usage/better management to avoid a leak
Back to top
View user's profile Send private message
akumakuja28
Master Cheater
Reputation: 16

Joined: 28 Jun 2015
Posts: 432

PostPosted: Wed Feb 08, 2017 7:45 pm    Post subject: Reply with quote

Whats your memory usage. Around 100 to 200 is normal(for me) when
Using timers.

_________________
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Feb 09, 2017 8:12 am    Post subject: Reply with quote

I also had such issues. I made a cheat, AA script (which in fact is embedded Lua script inside AA script)

This one:
Code:
[ENABLE]
{$Lua}
if syntaxcheck then return end

if readInteger'[POP.exe+6DB5A8]' == nil then return 'error' end

if FreezeSandAndPowerTanksTimer==nil then
  FreezeSandAndPowerTanksTimer=createTimer(nil,false)
  FreezeSandAndPowerTanksTimer.Interval = 50
  local readInteger,writeInteger=readInteger,writeInteger
  FreezeSandAndPowerTanksTimer.setOnTimer(
    function (t)
      local val = readInteger'[POP.exe+6DB5A8]+7C'
      if val then
        writeInteger('[POP.exe+6DB5A8]-4FC' , val)
        writeInteger('[POP.exe+6DB5A8]'     , val*2)
      end
    end
  )
end
FreezeSandAndPowerTanksTimer.Enabled = true
{$Asm}

[DISABLE]
{$Lua}
if syntaxcheck then return end
FreezeSandAndPowerTanksTimer.Enabled = false
{$Asm}


And memory usage was slowly climbing. Few kilobytes per 5 seconds.


So I added those as main Lua script:
Code:
collectgarbage('setstepmul',400)
collectgarbage('setpause',150)


Glare wrote:
if there's any additional methods I could apply for less mem usage/better management to avoid a leak

Avoid creating and destroying new objects. Try reuse already existing ones.

Also showing us your script can by handy.

_________________
Back to top
View user's profile Send private message MSN Messenger
akumakuja28
Master Cheater
Reputation: 16

Joined: 28 Jun 2015
Posts: 432

PostPosted: Thu Feb 09, 2017 10:08 am    Post subject: Reply with quote

mgr.inz.Player wrote:


So I added those as main Lua script:
Code:
collectgarbage('setstepmul',400)
collectgarbage('setpause',150)





Does tht keep you at a reasonable memory usage?
I have used collectgarbage() on a timer before, always felt like it was overkill, or unnecessary if I was not doing anything in Lua(Normal Game Breaking).
I just call it manually now. Its like clockwork anymore, every 10 or so changes and collectgarbage() gets a run. Your method seems promising tho.

_________________
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Feb 09, 2017 5:16 pm    Post subject: Reply with quote

Default values are 200 for each:
Code:
print('previous values',collectgarbage('setstepmul'),collectgarbage('setpause'))

>previous values 200 200

_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites