• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Does boolxpr variables need to be destroyed? (Dynamic trigger registration)

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
Hi all. If triggers are registered dynamically, do the boolxpr variables added to them need to be destroyed to prevent memory leak? Please see the following example if you have time, thanks a lot.
JASS:
function con takes nothing returns nothing
    .........
    call DestroyTrigger(GetTriggeringTrigger())
endfunction


function run takes nothing returns nothing
    local boolexpr expr = Condition(function con)
    local trigger trig = CreateTrigger()
    local unit target = GetSpellTargetUnit()
    call TriggerRegisterUnitEvent(trig,target,EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(trig,expr)
    set expr = null
    set trig = null
    set target = null
endfunction

function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterUnitEvent( t, gg_unit_Hpal_0000, EVENT_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(t, Condition(function run))
    set t = null
endfunction
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Only ones witg boolexpr in them as a result of using nativez like And and Or. Conditions are only made once and then reused. If they are destroyed, the trigger will have invalid data in it and will skip over them. This will result in a triggercondition leak until the trigger is destroyed or cleared.

For more power and speed, consider using Trigger from My Resources.
 
Level 11
Joined
Oct 11, 2012
Messages
711
Only ones witg boolexpr in them as a result of using nativez like And and Or..

Thanks for the reply, but can you explain more about this? I will use your resource but I just wanna know the principle of how it works. :) Do you mean the following two boolexpr variables need to be destroyed?
JASS:
function example takes nothing returns nothing
    local boolexpr expr1 = Condition(function test1) 
    local boolexpr expr2 = Condition(function test1) 
    if expr1 and expr2 then
    ........
    endif
    ......
endfunction
/* Is this what you mean, Nes? But doesn't this looks wrong? :) How can we put
 boolexpr in the if statement? I must misunderstood your point.... */
If they are destroyed, the trigger will have invalid data in it and will skip over them.
You are right, I also noticed this problem when I destroyed the condition. The trigger was skipped over. Thanks for the clarification.

Afaik it is still unclear wheter or not registering conditions causes leaks, but 2 conditions always generate the same handle, so I guess it shouldnt leak from the logical perspective

Thanks. Then I don't need to worry about it. :)

+Rep to both of u.
 
Thanks for the reply, but can you explain more about this? I will use your resource but I just wanna know the principle of how it works. :) Do you mean the following two boolexpr variables need to be destroyed?

No, those two boolexpr variables do not need to be destroyed.

He meant that if you create a boolexpr like this:
JASS:
function A takes nothing returns boolean
    return true
endfunction
function B takes nothing returns boolean
    return true
endfunction

function Example takes nothing returns nothing
    local boolexpr a = Condition(function A) // fine, will be cached and reused
    local boolexpr b = Condition(function B) // fine, will be cached and reused
    local boolexpr a_and_b = And(a, b) // not fine: new, separate boolexpr
    local boolexpr a_or_b = Or(a, b) // not fine: new, separate boolexpr
endfunction

Boolexprs generated through Condition() and Filter() are cached and reused each time you reference them, so you don't have to destroy them.
 
Level 11
Joined
Oct 11, 2012
Messages
711
No, those two boolexpr variables do not need to be destroyed.

He meant that if you create a boolexpr like this:
JASS:
function A takes nothing returns boolean
    return true
endfunction
function B takes nothing returns boolean
    return true
endfunction

function Example takes nothing returns nothing
    local boolexpr a = Condition(function A) // fine, will be cached and reused
    local boolexpr b = Condition(function B) // fine, will be cached and reused
    local boolexpr a_and_b = And(a, b) // not fine: new, separate boolexpr
    local boolexpr a_or_b = Or(a, b) // not fine: new, separate boolexpr
endfunction

Boolexprs generated through Condition() and Filter() are cached and reused each time you reference them, so you don't have to destroy them.

Thank you so much, PnF. I knew you would reply! LOL ++++Rep
 
Status
Not open for further replies.
Top