• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Memory leaks with timers

Status
Not open for further replies.
Level 3
Joined
Jan 29, 2021
Messages
34
Hello guys.
I have map 2d platformer, I wrote lots of scripts that make computers complete levels of this game kind of perfectly
For all that scripts I used sort of Movement API(created by me) from the original map and LOTS AND LOTS OF TIMERS

So, for example how part of my script looks like:
Code:
function Level_1_5_Help_7 takes nothing returns nothing
local timer t1 = CreateTimer()
local timer t2 = CreateTimer()
local timer t3 = CreateTimer()
local timer t4 = CreateTimer()
local timer t5 = CreateTimer()
local timer t6 = CreateTimer()
local timer t7 = CreateTimer()
local timer t8 = CreateTimer()

call TimerStart(t1, 0, false, function Right7)
call TimerStart(t2, 0.2, false, function StopRight7)
call TimerStart(t3, 0.6, false, function Right7)
call TimerStart(t4, 0.68, false, function StopRight7)
call TimerStart(t5, 1.08, false, function Right7)
call TimerStart(t6, 1.16, false, function StopRight7)
call TimerStart(t7, 1.56, false, function Right7)
call TimerStart(t8, 1.64, false, function StopRight7)
endfunction

Now, imagine that there are lots and TONS of same looking functions with even more timers inside
Imagine that amount of code only for this scripts is ~5k lines of code

Now the question is
  • Do I have to null every local timer at the end of its function? Does unnulled timers cause some memory leaks?
  • When I start script in the game sometimes FPS start lowering huge, what to do with that?
  • Again, how to solve FPS lowering in general case? At the moment I have pretty weak computer(some ppl say its ancient wooden one in compare to modern ones) Would the more powerfull PC help?
 
Level 3
Joined
Jan 29, 2021
Messages
34
Hi, thanks for the advice.
The problem is...
Well, how to say it, just try to imagine that I"m fucking retard with IQ < 30
So, could you explain what is that TimerUtils Library, where and how do I get it, how to use it/import it?
Thanks
 
Level 9
Joined
Jul 20, 2018
Messages
177
Do I have to null every local timer at the end of its function? Does unnulled timers cause some memory leaks?
You should nullify all local handles.

But you can reduce your code

JASS:
function Level_1_5_Help_7 takes nothing returns nothing
    call TimerStart(CreateTimer(), 0, false, function Right7)
    call TimerStart(CreateTimer(), 0.2, false, function StopRight7)
    call TimerStart(CreateTimer(), 0.6, false, function Right7)
    call TimerStart(CreateTimer(), 0.68, false, function StopRight7)
    call TimerStart(CreateTimer(), 1.08, false, function Right7)
    call TimerStart(CreateTimer(), 1.16, false, function StopRight7)
    call TimerStart(CreateTimer(), 1.56, false, function Right7)
    call TimerStart(CreateTimer(), 1.64, false, function StopRight7)
endfunction

In all callbacks you should destroy timers.

JASS:
function Right7 takes nothing returns nothing
    // code
    call PauseTimer(GetExpiredTimer())  // if periodic
    call DestroyTimer(GetExpiredTimer())
    // variable nulling
endfunction

Why all may spaces got removed in code after newline?

But as suggested above, for not an experienced mapmaker TimerUtils is better.

So, could you explain what is that TimerUtils Library, where and how do I get it, how to use it/import it?
Just search "TimerUtils warcraft 3"
 
Last edited:
Status
Not open for further replies.
Top