Memory Leaks and Conditions

Leo

New Member
Reaction score
14
I know memory leaks occur when actions are called, but do they also occur when conditions are checked?

For example, if I put a condition on a trigger that checks the number of units owned by the owner of a particular unit, would this condition leak.

I know using unit groups in actions leak unless the group is set to a variable, so I was wondering if this applies to conditions too, and if the condition would need to reference a prexisting variable set to number of units owned by owner of the unit.

This would apply to a trigger that is called often, so if it does leak, its important that I know.

Sorry, I'd copy exact code by editor is closed and my comp is running slow.
 
P

Pawnable

Guest
Well, I have never had a memory leak problem with conditions... but it would be good just to be sure and make another trigger.
 

Luth

Lex Luthor!
Reaction score
41
Conditions can leak all the same, sure. Sometimes you'll have to convert it to custom script to clean it up.
 

Leo

New Member
Reaction score
14
another leak question

So I have multiple triggers that periodically spawn units at locations. Which is a more efficient and leakless way of doing them.

Should I set variables to the locations once at map initialization and call these variables every time the trigger runs, or should I set the variables within the spawn trigger and destroy them each time it finishes running.

This will apply to nearly 20 in map triggers.
 
M

Maximus

Guest
My suggestions:
1. Convert the condition into if / then /else, before the if then else set the thing, if the condition not reached, skip remaining actions. :D
2. Don't know... Sorry...
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
1. Convert to custom script and fix the leaks there, when your are at the stage when you want to fix leaks in your conditions then it is much easier to just learn jass and code good code from the begining insteed of cleaning up your own mess afterwards.
Actualy, I think that as soon you start worry about memory leaks you should drop the GUI asap.

2. Using 'static' values is always better than re-creating the 'same' location every time.
 

Leo

New Member
Reaction score
14
Maximus: Yea I know thats one option, but my knowledge of conditions is more limited and I wanted get to the bottom of the issue.

phyrex1an: Well I know I have to convert to custom text and just code in JASS. I use it when I can, though, I'm not that great with it and I prefer to use GUI if the situation allows.

So would the following code work and be leakless? Note: Im not on my home computer so its just a sample, and not the actual trigger im using in game.

I appreciate the help.

Code:
function Trig_test_Conditions takes nothing returns boolean
    set udg_temgroup = GetUnitsOfPlayerAll(Player(0))
    if ( not ( CountUnitsInGroup(udg_temgroup) == 100 ) ) then
        return false
    call DestroyGroup ( udg_temgroup )
    endif
    return true
endfunction

function Trig_test_Actions takes nothing returns nothing
    call KillUnit( testunit )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test_ = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_test, Condition( function Trig_test_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
No, but you almost got it :)

Code:
function Trig_test_Conditions takes nothing returns boolean
    local group temgroup = GetUnitsOfPlayerAll(Player(0))
    local integer i = CountUnitsInGroup(temgroup)
    call DestroyGroup(temgroup)
    set temgroup = null
    return i == 100
endfunction

With your function, it will never reach the DestroyGroup(udg_temgroup).
 

Leo

New Member
Reaction score
14
Ok ignore my previous post, I figured out my own question.

Now here is the actual code from my map. Any suggestions for improvement would be welcome

One last question, are local variables local only to the a function or are they local to the whole trigger?


Code:
function Trig_test_Func003001 takes nothing returns boolean
    return ( GetOwningPlayer(gg_unit_h004_0016) != Player(PLAYER_NEUTRAL_PASSIVE) )
endfunction

function Trig_test_Func003002 takes nothing returns boolean
    local player baseowner = GetOwningPlayer(gg_unit_h004_0016)
    local group tempgroup = GetUnitsOfPlayerAll(baseowner)
    local integer a = CountUnitsInGroup(tempgroup)
    set tempgroup = null
    set baseowner = null
    return ( a < 400 )
endfunction

function Trig_test_Conditions takes nothing returns boolean
    if ( not GetBooleanAnd( Trig_test_Func003001(), Trig_test_Func003002() ) ) then
        return false
    endif
    return true
endfunction

function Trig_test_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( 2, 'nsty', GetOwningPlayer(gg_unit_h004_0016), udg_spawnpoints[0], bj_UNIT_FACING )
    call CreateNUnitsAtLoc( 1, 'nsts', GetOwningPlayer(gg_unit_h004_0016), udg_spawnpoints[0], bj_UNIT_FACING )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_test, udg_Timer )
    call TriggerAddCondition( gg_trg_test, Condition( function Trig_test_Conditions ) )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction
 

exge

New Member
Reaction score
15
err .. its called local for a reason right?
so i think it should be only in the func
 
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