1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The reforging of the races is complete. Come see the 14th Techtree Contest Results.
    Dismiss Notice
  4. It's time to choose your horse in the race - the 32nd Modeling Contest Poll is up!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Things That Leak

Discussion in 'Triggers & Scripts' started by Ralle, Jun 10, 2007.

  1. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    I haven't experienced any problems with it so far... :/
     
  2. GST_Nemisis

    GST_Nemisis

    Joined:
    Jan 5, 2005
    Messages:
    3,600
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    here is a question for you, when a place (or point) is written to the memory but is used multiple times does it still leak or not? so say if you wanted to spawn something in the middle of somewhere ever 5 seconds forever, would it lag because although you are writing an address to the memory, you are re-using that address constantly, so there is no point in destroying it when 5 seconds later it is going to be re-written.
     
  3. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    It's a new point every time. Points aren't stored the same way as strings/boolexprs.

    Think units. If you create 2 footmen, are they the same footmen, just because you spawned them both at (Position of (Barracks)) and they have the same stats/type? No, warcraft creates both footmen, not just one.
     
  4. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    A few examples on location leaks - and removing them:
    Let's say each loop runs 5 times!
    This leaks:
    Code (vJASS):
    loop
    call CreateSpecialEffectLoc(Location(0,0), "")
    call TriggerSleepAction(1)
    endloop

    ->5 leaks

    This does not leak:
    Code (vJASS):
    set loc = Location(0,0)
    loop
    call CreateSpecialEffectLoc(loc, "")
    call TriggerSleepAction(1)
    endloop
    call RemoveLocation(loc)

    ->0 leaks

    But this one does leak again:
    Code (vJASS):
    loop
    set loc = Location(0,0)
    call CreateSpecialEffectLoc(loc, "")
    call TriggerSleepAction(1)
    endloop
    call RemoveLocation(loc)

    ->4 leaks (the last one is removed)

    While this one does not:
    Code (vJASS):
    loop
    set loc = Location(0,0)
     call CreateSpecialEffectLoc(loc, "")
     call RemoveLocation(loc)
     call TriggerSleepAction(1)
     endloop

    ->0 leaks - but this is inefficent
     
  5. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Let's integrate previous posts so Ralle can put it in his first post (leaks are important!):

    Strings: They technically leak, there is no way to clean those leaks, but you can avoid it by not having a lot of different strings (don't generate a random string every 0.01 seconds or stuff like that), WE uses the same strings once generated.

    Handles: They should be nullified when in a variable, because then a pointer will be left causing a leak. Handles are everything except: integer, real, string, boolean, code
    Example:

    Code (vJASS):
    function NullifyHandles takes nothing returns nothing
        local unit c = GetTriggerUnit()
        local location l = GetSpellTargetLoc()
        local timer t = CreateTimer()
        local integer i = GetUnitAbilityLevel(c, 'A000') // don't pay attention to this 'A000'
        // do stuff with those.....
        call RemoveLocation(l)
        call DestroyTimer() // this depends on the situation, maybe this will be done elsewhere
        set c = null
        set l = null
        set t = null
    endfunction


    Note that integer is not nullified.

    Triggers, Trigger Actions, Trigger Conditions: Those leaks should be fixed like this:

    Code (vJASS):
    function DummyCondition takes nothing returns boolean
        return true
    endfunction

    function DummyAction takes nothing returns nothing
        call KillUnit(GetTriggerUnit())
    endfunction

    function CleanTriggerLeaks takes nothing returns nothing
        local trigger t = CreateTrigger()
        local triggercondition tc = TriggerAddCondition(t, Condition(function DummyConditions))
        local triggeraction ta = TriggerAddAction(t, function DummyAction)
        //........
        call TriggerRemoveCondition(t, tc)
        call TriggerRemoveAction(t, ta)
        call DestroyTrigger(t)
        set t = null     // note...
        set tc = null   // ...the nullifications...
        set ta = null   // ...here :P
    endfunction


    Boolexprs: I don't know what exactly boolexprs are, but I've heard they are a string-based type (whatever that means). When using them as a trigger condition, they should not be destroyed (because then the condition is lost too)! But when using them as a group filter (Pick Every Unit In Unit Group Matching) they should be destroyed:

    Code (vJASS):
    function DummyFilter takes nothing returns boolean
        return not IsUnitType(GetFilterUnit(), UNIT_TYPE_DEAD) // this filters only units that are [B]alive[/B]
    endfunction

    function CleanBoolexprLeak takes nothing returns nothing
        local group g = CreateGroup()
        local boolexpr be = Condition(function DummyFilter)
        local real x = 0
        local real y = 0
        call GroupEnumUnitsInRange(g, x, y, 500, be)
        call DestroyBoolExpr(be)
    endfunction


    Weather Effects: Should be fixed like this:

    Code (vJASS):
    function CleanWeatherEffectLeak takes nothing returns nothing
        local weathereffect we = AddWeatherEffect('RAhr', bj_mapInitialPlayableArea) // 'RAhr' is id of Ashenvale Rain (Heavy)
        call EnableWeatherEffect(we) // this is necessary for a weather effect to even work! (to show rain)
        // do stuff.....
        call RemoveWeatherEffect(we)
        set we = null
    endfunction


    Regions/Rects: In JASS there is a region and there is a rect. Don't ask me what's the difference because I don't know. In GUI they are both called regions. Region leaks should be removed like this:

    • Regions
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Some Spell
      • Actions
        • Set Loc1 = (Position of (Triggering unit))
        • Set Region = (Region centered at Loc with size (300.00, 300.00))
        • Set Loc2 = (Center of Region)
        • Unit - Create 1 Footman for Player 1 (Red) at Loc facing Default building facing degrees
        • Custom script: call RemoveLocation(udg_Loc1)
        • Custom script: call RemoveRect(udg_Region)
        • Custom script: call RemoveLocation(udg_Loc2)


    Pask had some good examples there, put that also Ralle. Those are common leaks, there are tons of other leaks, but they are so rare that it doesn't even matter. I probably forgot a leak fix or two, so if anyone knows what I've missed, please tell.

    I hope it's ok I revived this thread, but I want it to be sticky, can you do that Ralle?
     
  6. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    As I experienced, most scripters know how to clean leaks in Jass. I think Ralle's main issue was to collect the ones that can occur in GUI, so I think triggers, triggeractions, boolexpr-s, etc could be left out.
     
  7. Pyritie

    Pyritie

    Joined:
    Nov 26, 2006
    Messages:
    11,356
    Resources:
    60
    Models:
    30
    Icons:
    9
    Packs:
    3
    Skins:
    12
    Tools:
    1
    Maps:
    1
    Tutorials:
    4
    Resources:
    60
    Has everyone forgotten about
    • Custom script: set bj_wantDestroyGroup = true
    • Unit group - pick every unit in...


    This way you do not need to bother with a variable at all!
     
  8. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Pyritie, you're the one who forgot to READ THE FIRST POST...
     
  9. prune1

    prune1

    Joined:
    May 16, 2007
    Messages:
    4
    Resources:
    0
    Resources:
    0
    Hello all, need a little help please.

    First of all, just how much will this improve my map, realistically, I mean it's obviously relative but I mean how much would say, going to the trouble of editing a map that's well on the way and destroying 20 or so unit groups, same amount of player groups (not All players though, if i understand correctly, they don't leak?) and setting dynamic locations for about, once again, 20 instances throught the triggers, and such and destroying them too, actually improve performance?

    I think I will go ahead and do this regardless, just because I'm a bit of a perfectionist. :wink:

    I would also like some clarification as to the custom script for destroying destrutible groups, e.g, I pick all destructibles in a region (created in the editor - do I need to set these regions to a variable too?...) and kill picked destructible. I mean, the unit group one is called DestroyGroup, the player group one is DestroyForce, so what is it for destructibles?

    Oh, and an example for it like those on the first post would be great, much easier to see! :grin:

    Thanks in advance for any help!

    Edit: Also, in ref to this, again from first post:

    Set GroupVar = Pick every unit in (Playable Map Area)
    Unit Group - Pick every unit in GroupVar and do (Unit - Hide (Picked unit))
    Custom script: call DestroyGroup(udg_GroupVar)

    This is useful is you want to use the group more than one time in the trigger.


    When it says its useful if you want to use it multiple times in one trigger, exactly what does it mean? That you can hold off on the Custom script: call DestroyGroup(udg_GroupVar) until you're done using that group? Or you have to do the whole thing everytime.

    And which is more efficient, this or the little one-liner that is something along the lines of 'want to destroy trigger'? (Second seems too easy, must be less efficient? :p)
     
    Last edited: Jun 27, 2007
  10. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    You won't really notice efficiency change for destroying 20 group/locations/.. leaks. Leaks cause problems mainly in spells, as they are casted more than one time during the game. If it creates let's say 50 location leaks, and is cast 50 times/game, that's 2500 leaks/game. For only one spell!

    You don't have to set "generated regions" - that's what they're called - into a variable. They are already set to a generated variable. They look like: gg_rct_RegionName
    New regions will be called gg_rct_Region000, gg_rct_Region001, until you change their name. Hope it's clear.
    Umm... Destructable groups??

    The group-destroying method you wrote is more efficient if you still want to use that group more than one time.
    Set GroupVar = Pick ...
    Unit group - Pick every unit in GroupVar ...
    Do something
    Maybe Wait x seconds
    Do something else
    Unit group - Pick every unit in GroupVar ...
    call DestroyGroup(udg_GroupVar)

    With bj_wantDestroyGroup, it would create and destroy two groups. - Less efficient.

    I hope I cleared everything ;)
     
  11. Pyritie

    Pyritie

    Joined:
    Nov 26, 2006
    Messages:
    11,356
    Resources:
    60
    Models:
    30
    Icons:
    9
    Packs:
    3
    Skins:
    12
    Tools:
    1
    Maps:
    1
    Tutorials:
    4
    Resources:
    60
    Yes if you're using the group more than once you stick it into a variable, but if it's only once then you can just do "set bjWantDestroyGroup = true".

    I read the first post and I could've sworn I didn't see that.
     
  12. prune1

    prune1

    Joined:
    May 16, 2007
    Messages:
    4
    Resources:
    0
    Resources:
    0
    Thanks for all that.

    And the destructible groups thing...yes, I realise there is no destructible group type triggers in the game, so perhaps its not a group.

    It's just that it involves picking every destructible in a region and doing something to it...it sounds, going by what I've learnt so far, that it might be the sort of thing that leaks, but I guess not? (I'm focusing on the 'pick every unit' thing as my reason for thinking its a leak, but you're right, no mention of it being a 'group' anywhere...so just set me clear here: The above will not leak?).
     
  13. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Before picking every unit in whatever you should do set bj_wantDestroyGroup = true, because that gives a signal to the ForGroupBJ function to destroy the group it's "ForGrouping" :p. Don't get the wrong idea, it is a leak.

    I have a question related to boolexpr leaks. So boolexprs generated with And() or Or() leak. But what about boolexprs connected with "and" and "or"? Example:

    Code (vJASS):
    function Boolexpr takes nothing returns boolean
        return not IsUnitType(GetFilterUnit(), UNIT_TYPE_DEAD) and IsUnitEnemy(GetFilterUnit(), Player(0))
    endfunction


    So this doesn't leak?
     
  14. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Booleans are connecter with 'and', 'or' and not boolexpr-s. So they do not leak.

    btw: UNIT_TYPE_DEAD? :)
     
  15. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    I use UNIT_TYPE_DEAD because GetUnitState()<=0 is not accurate, it may not always work.
     
  16. bbfreak

    bbfreak

    Joined:
    Oct 12, 2004
    Messages:
    109
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Do Environment effects leak?
     
  17. Razorbrain

    Razorbrain

    Joined:
    Aug 18, 2006
    Messages:
    1,165
    Resources:
    1
    Maps:
    1
    Resources:
    1
    yes, but there is a trigger for removing them
    • Environment - Remove (your weather effect)


    i have a problem, this location removal wont work :(
    • Custom script: call RemoveLocation(udg_Region)

    theres supposed to be some kind of (rect) problem :/
     
    Last edited: Jul 17, 2007
  18. Lingonberryjam

    Lingonberryjam

    Joined:
    Feb 25, 2005
    Messages:
    230
    Resources:
    0
    Resources:
    0
    I cant sort this out still... does this leak:
    • Does this Leak
      • Events
        • Someone answers this
      • Conditions
      • Actions
        • Set Location[4] = (Center of MerchantSpot <gen>)
        • Cinematic - Ping minimap for (All players) at Location[4] for 1.00 seconds, using a Flashy ping of color (30.00%, 100.00%, 100.00%)
        • Unit - Create 1 Elementar Master for Neutral Passive at Location[4] facing Default building facing degrees
        • Custom script: call RemoveLocation( udg_Location[4] )

    .
    Or do i have to use the custom script removal twice in the trigger, or is it enough to do so only once per trigger?
     
  19. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,161
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Sure it does.

    Code (vJASS):
    native And              takes boolexpr operandA, boolexpr operandB returns boolexpr
    native Or               takes boolexpr operandA, boolexpr operandB returns boolexpr
    native Not              takes boolexpr operand returns boolexpr
     
  20. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    So you're saying it's the same thing? Someone told me that it doesn't always work (when something specifically happens which messes with life)