Do Local Triggers leak?

jonadrian619

-___-
Reaction score
242
I've been experimenting on making Local Triggers. Here's an example of a trigger I've converted to JASS and made local triggers.

JASS:
function Sample takes nothing returns nothing
endfunction

//========================================================
function InitTrig_Sample takes nothing returns nothing
    local trigger t
    set t = CreateTrigger()
    call TriggerRegister[whatever event](t, whatever)
    call TriggerAddAction(t, function Sample)
endfunction


In daelin's tutorial it said that Triggers themselves leak. Do local triggers leak or triggers created through functions? If yes then how can I remove the leak?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Isn't it "DestroyTrigger"?

The action function will leak.
Though, if you're desperate enough, you could do it all in the condition function (and return false when done)...
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Local triggers do leak. The reason global triggers don't leak is becuase you can always access them, thus their data is never lost, thus it is not a leak. It is recommended to remove local triggers, and if possible even global triggers (if they run only once).

JASS:


Note, it is better to use conditions as local triggers' actions, assuming you don't need a wait.
 
Reaction score
333
If you're going to be using your trigger for the entire game, then the leak does not matter.

If you only wanted it to run once, though, you might do something like this:

JASS:
function Sample takes nothing returns boolean
    local trigger t = GetTriggeringTrigger()
    //Do stuff..
    call DisableTrigger(t) //if this actually serves a purpose
    call DestroyTrigger(t)
    set t = null
    return false
endfunction

//========================================================
function InitTrig_Sample takes nothing returns nothing
    local trigger t
    set t = CreateTrigger()
    call TriggerRegisterWhateverEvent(t, whatever)
    call TriggerAddCondition(t, Condition(function Sample))

    set t = null
endfunction
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> If you only wanted it to run once

No, that will not do. You should destroy any local trigger that you don't want want running the whole game. Even if you want it to run ten times, if you want it to stop running at some point, then you need to destroy it when you are done, else there is a leak right there.
 
Reaction score
333
> If you only wanted it to run once

No, that will not do. You should destroy any local trigger that you don't want want running the whole game. Even if you want it to run ten times, if you want it to stop running at some point, then you need to destroy it when you are done, else there is a leak right there.

The trigger will not work if you destroy it before it has a chance to run. I'm fairly sure the Jass I've posted works fine. as long as t is nulled in the "InitTrig_Sample" function, the trigger will not leak.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
There is no problem with what you posted, assuming that you want the trigger to run only once. However if you want to run several times / until some condition is met, then you are going to need to find another approace. Possibly a simple if / then / else function would do.
 

ertaboy356b

Old School Gamer
Reaction score
86
You can use Condition as an Action.. That way, you don't have to worry bout leaks.. But it's not so friendly with waits..
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
hmm, maybe sth like this...

JASS:
function TriggerCondition takes nothing returns boolean
    local trigger t=GetTriggeringTrigger()
    if GetTriggerEvalCount(t)<=10 then //place number here
        return true
    else
        call DestroyTrigger(t)
        set t = null
    endif
    return false
endfunction

//========================================================
function InitTrig_Sample takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(t,Player(0),EVENT_PLAYER_UNIT_DEATH,null)
    call TriggerAddCondition(t, Condition(function TriggerCondition))
    //call TriggerAddAction(t, function DoSomething)
endfunction
 

SFilip

Gone but not forgotten
Reaction score
634
I don't see what the problem is.
Doesn't matter if it's a global variable or a local variable. Every CreateTrigger call must have a DestroyTrigger that takes care of it at some point. But this doesn't mean you should go around destroying all of your gg_ triggers, they are already taken care of when the map ends. Only the ones created when, for example, a spell is cast need to be destroyed.
 

Silvenon

New Member
Reaction score
19
I don't understand what is the problem if one trigger isn't nullified or/and destroyed. InitTrig_s are called only once and it is no problem if a trigger isn't destroyed. Like SFilip said, only when creating a spell, leaks are important to clean (and in some other periodic situations). That's why most one-shot triggers are made in GUI, because it doesn't really matter much (same reason people don't inline TriggerReigsterAnyUnitEventBJ).
 

Sooda

Diversity enchants
Reaction score
318
> same reason people don't inline TriggerReigsterAnyUnitEventBJ

Majority maybe but I' m in minority. There was thing where you had to destroy first trigger actions with one certain native function then wait 10.00 seconds and only after that you could destroy trigger once and for all.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
> same reason people don't inline TriggerReigsterAnyUnitEventBJ

Majority maybe but I' m in minority. There was thing where you had to destroy first trigger actions with one certain native function then wait 10.00 seconds and only after that you could destroy trigger once and for all.

Probably was proved to be false. But maybe true.

The native, from what I remember, is probably TriggerRemoveActions or w/e it was. Really, I don't understand why people get so hectic about leaks unless they are posting the code. The best bet is probably just to destroy all local/global variables then null it if it is a local.

Except for generated global triggers ofcourse. :p

Oh yea, btw, instead of:
JASS:
local trigger t
set t = CreateTrigger()


Do this:
JASS:


Lol, I know it is probably just an example, but oh well. xD
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> waaaks!

Well, each time you do that, you create a leak.
 
Reaction score
456
>Well, each time you do that, you create a leak.
Are you sure? Creating an unit variable and nulling it without removing the unit doesn't leak.
 

SFilip

Gone but not forgotten
Reaction score
634
Units can die. Triggers just stay around until the end of the game, taking memory.
Every Create<whatever> creates a leak if it doesn't have a Destroy<whatever> or Remove<whatever> that will take care of it. However gg triggers aren't a problem as they're only created once and automatically destroyed when the game ends.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> and automatically destroyed when the game ends.

Everything is destroyed when the game ends... I agree that gg triggers aren't a big problem becuase they are created only once, however it wouldn't hurt destroying them when you are done.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top