• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Nulling local triggers

Status
Not open for further replies.
Do local triggers need to be nulled? I was under the impression that they didn't, but today someone suggested in my spell submission that I should null the local trigger created in my OnInit function. Is there any point in doing this?

I guess to clarify,

JASS:
private function OnInit takes nothing returns nothing
        local trigger trig = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(trig,Condition(function OnSpell))
        set trig = null
endfunction

Is this fine? Is it fine if I don't null the trigger too?

Iirc, making triggers like this creates an unavoidable leak anyways, so there would be no point in nulling it?
 
Level 13
Joined
Sep 13, 2010
Messages
550
It depends. Do you know handle leaks, right? This prevents leaking a handle if you ever destroy the trigger. If not, then it was useless, but the hardcore jass fags here insist nulling every handle type.

Anyways I didn't know that triggers generate serious leaks.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
It decreases the reference counter at least. Maybe some tiny reference would be cleared up.

@Geries: The point being made here was that the trigger is only called locally within the function, so the trigger cannot be destroyed although I do not like that the TC makes it sound like the trigger object would be local.

Not all handle types need their variables to be nulled. Only those that count to the big stack beyond 1mio. Those are called agents in most cases. Anyway, it seems more simple and routinely to just nullify everything.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Do local triggers need to be nulled?
If they are destroyed? Yes
If the triggers themselves are left to leak (persist the entire session)? No

Local handles only need to be nulled if the index is intended to be recycled at a later time during the session as otherwise they cause a reference counter leak. Local handles that are declared as function arguments do not need to be nulled, the reference leak is only with locals defined with the "local" key word.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I wonder, what abou globals? if I have a global location l, then I do
JASS:
set l = Location(0, 0)
call RemoveLocation(l)
set l = Location(1, 0)

will that leak? :D
btw sorry if this is considered thread hijacking but Im curious and Ill not post another thread just for this small question
 
Status
Not open for further replies.
Top