• 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.

Run This Trigger

Status
Not open for further replies.

noj

noj

Level 4
Joined
Jan 16, 2006
Messages
89
Code:
Trigger - Run (This trigger) (checking conditions)

Can this line cause memory accumulation when its in a infinite loop?

I know in programming when you call a function the calling function will cease activity until the called function returns something. If this line of code acts as such then it will not only cause a infinite loop assuming conditions do not change, but it will also stack previous 'calling' functions. Therefore accumulating memory usage every time the line of code is run. none of the triggers will actually end and in result none of the memory they use will be removed.
Does anyone know if this is how the code runs, and if there is a better alternative to restart a trigger from the start?
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
This is how the code runs:

JASS:
function ConditionalTriggerExecute takes trigger trig returns nothing
    if TriggerEvaluate(trig) then
        call TriggerExecute(trig)
    endif
endfunction

And no it doesn't return anything ;)

If you're going to use this within a infinite loop, just make sure that there is delay within the loop.
Running the same trigger simultaniously at excesive high speed might cause some trouble if the trigger is not MUI.

none of the triggers will actually end and in result none of the memory they use will be removed.
The triggers do end, but are executed again before they end unless there is delay between the execution.

Let me put it this way:

I call a function.
While the function is still executing some actions, I call it again.
Now will the first time I called the function stop executing and stay in memory?
No, the first call will finish whatever it was doing and will be removed afterwards.
However, if you are going to use for example global variables within this function.
Then that means that the global variable can be altered by the second time I call the function causing the first call to have incorrect values within the global variable.

Doing something like this in a highspeed loop without any delay simply takes up a lot of memory but it would stay constant.
By adding delay you reduce the amount of memory it needs.
Since less functions are then called within that time.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
@Hashje: It's not about the return value but when the function ends.

An infinite loop without delay does not make sense as it would freeze everything respectively wc3 recognizes the overflow and closes.

So the question would be whether

Wait
Run This Trigger

stacks up. This is not the case because triggers do not wait for Waits of triggers they run.

1st instance

Wait
Run This Trigger

2nd instance

Wait --> there's a wait here, so 2nd instance is pushed back in the execution stack and 1st can continue its stuff
Run This Trigger

You can easily test this with

Wait
Run This Trigger
Display("blub")

I do not know whether it keeps history of all the parent functions, which could be a possible leak. Then again, it's not advised to use Waits anyway rather timers which are much cleaner and all.
 

noj

noj

Level 4
Joined
Jan 16, 2006
Messages
89
Thanks. Its abnormal of programming (as I'm use to) to continue a function when it makes a call, unless there is multithreading specifically designed into it.

Wait
Run This Trigger
Display("blub")

Was a ideal way to disprove my suspicion.

solved
 
Last edited:
Status
Not open for further replies.
Top