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 havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. 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. plumsy460

    plumsy460

    Joined:
    Oct 2, 2013
    Messages:
    272
    Resources:
    0
    Resources:
    0
    Does it leak to use the condition "Unit-Type Comparison"?
     
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    No leak here.
     
  3. Neversleeping

    Neversleeping

    Joined:
    Jan 6, 2010
    Messages:
    114
    Resources:
    1
    Maps:
    1
    Resources:
    1
    • waypointA1
      • Events
        • Unit - A unit enters waypoint1 <gen>
      • Conditions
        • (Owner of (Triggering unit)) Equal to Player 2 (Blue)
      • Actions
        • (Unit - Order (Triggering unit) to Attack-Move To (Center of waypont2 <gen>))


    Quick question. Is the following the correct way of stopping the above leak?

    • waypointA1
      • Events
        • Unit - A unit enters waypoint1 <gen>
      • Conditions
        • (Owner of (Triggering unit)) Equal to Player 2 (Blue)
      • Actions
        • Set UnitVar = (Triggering unit)
        • (Unit - Order (UnitVar) to Attack-Move To (Center of waypont2 <gen>)
        • Custom script: call DestroyGroup(udg_UnitVar)
     
  4. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Using "TriggeringUnit" does not leak. Storing it into a unit variable makes sense, if you use it more than once in further actions to avoid more function calls.
    (TriggeringUnit calls a function each time, so: using variable > function calls)

    But back to your leak question, you actually leak a location. Store the point into a variable, and remove the location afterwerds. Read the "Location" chapter in this tutorial.
    ("Center of waypont2" leaks)

    Also, "call DestroyGroup()" is only used for UnitGroups. You don't have any UnitGroup here.
     
  5. Neversleeping

    Neversleeping

    Joined:
    Jan 6, 2010
    Messages:
    114
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I meant to write DestroyUnit or something, but that's seemingly irrelevant as it's the location variable that leaks.
    Let me do another attempt...

    • waypointA1
      • Events
        • Unit - A unit enters waypoint1 <gen>
      • Conditions
        • (Owner of (Triggering unit)) Equal to Player 2 (Blue)
      • Actions
        • Set TempLocation = (Center of waypont2 <gen>)
        • (Unit - Order (Triggering unit) to Attack-Move To (TempLocation))
        • Custom script: call RemoveLocation(udg_TempLocation)
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    You can't and don't need to destroy "TriggeringUnit". It does not leak. Anyway, now you're doing good about the location leak. :)
     
  7. Neversleeping

    Neversleeping

    Joined:
    Jan 6, 2010
    Messages:
    114
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Brilliant! thanks.

    Oh, one more question. Is it enough to have a single "TempLocation" variable if it's a lot of similiar triggers going on practically at the same time? None of them has any wait-functions, so I presume a single trigger is always finished before another starts?
     
  8. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Yes, it is absolutly enough to use one variable for these stuff if it gets cleaned immediatly after usage.

    They won't come in conflict, because there are never two functions running the in exact the same time... as you said correctly, they run after each other.
     
  9. Neversleeping

    Neversleeping

    Joined:
    Jan 6, 2010
    Messages:
    114
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Gotcha.
    As I started going through the triggers and plug the leaks, yet another thing came to mind. Sorry about all the questions, hope you bear with me! :) I would totally Rep you if I could at the moment.

    If I always use use Set TEMP_Point = (Some Point <gen>) and always make this point the target of the orders, is it really necessary to use RemoveLocation()? I mean, will it not then overwrite the information each time, taking no extra memory space?
     
  10. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    If you're using a "temp" variable, I would say yes. Because you must pay attention here. You must ensure that you free the memory before you set your variable to a new value.

    Set tempLoc = CentreOf_A
    ...
    Set tempLoc = CentreOf_B
    call RemoveLocation(udg_tempLoc)
    ^leak because I didnt free memory before I reused the variable.

    For constant unit patrols it would make sense to use location variables which gets initialized once and will never be overwritten again or destroyed.

    Init-trigger:
    Set RunPoint1 = CentreOf_A
    Set Runpoint2 = CentreOf_B

    A Unit Enters Region1
    Unit - Order TriggeringUnit Move to RunPoint1

    A Unit Enters Region2
    Unit - Order TriggeringUnit Move to RunPoint2

    So in these three triggers you see I set the points once, and they never get touched again. If you can ensure this, then you can do like this.

    Contra is that you need to create more variables instead of only one "temp" variable.

    If you have more questions you can directly message me to discuss it. :csmile:
     
  11. Tirlititi

    Tirlititi

    Joined:
    Jul 11, 2010
    Messages:
    396
    Resources:
    12
    Models:
    6
    Maps:
    2
    Spells:
    3
    JASS:
    1
    Resources:
    12
    Two triggers may run "at the same time" even if there is no wait. It happens when an action done in a trigger triggers the event of another one.
    Example :
    • Events
      • Player - Some random event
    • Actions
      • Player - Display "Step 1" to (All Players)
      • Unit - Order UNIT to move to LOCATION
      • Player - Display "Step 3" to (All Players)


    • Events
      • Unit - A unit is given an order targeting a point
    • Actions
      • Player - Display "Step 2" to (All Players)


    The texts are displayed in the order 1, 2, 3 there (the second trigger runs in the middle of the execution of the first, which resumes once this second trigger's run is over).

    This kind of situation is not that much frequent but it can be troublesome (and generate more bugs than a simple memory leak). Be cautious with giving orders, giving/removing items and moving units in particular.
     
  12. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    But removing an item (and widget in general) is not something instant, right ?
    However killing is instant i think.

    I also remember i had an hard time debugging a special case, i tried to ordered an unit (no target, or widget target, or point target) on some order event (no target, or widget target or point target), but the order was not instant and then the check was screwed, but maybe it was just because i paused the unit (can't remember if i paused it or not).
     
  13. Tirlititi

    Tirlititi

    Joined:
    Jul 11, 2010
    Messages:
    396
    Resources:
    12
    Models:
    6
    Maps:
    2
    Spells:
    3
    JASS:
    1
    Resources:
    12
    I don't remember about the "remove unit" thing. I think the unit is physically removed from the game instantatly (maybe triggering some "death" events or some order events, when they have skills like "defend") and the datas and handle are flushed after a 0 wait. But that's barelly a guess.

    For the order, I think it's because it was stuned or paused indeed ^^
    Orders given while a unit is stunned are activated only once the stun ends. That I remember.
     
  14. frettory

    frettory

    Joined:
    Jan 19, 2012
    Messages:
    51
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Do regions leak?
     
  15. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Just using a region does not leak. But it's still an agent, so you have to remove & null it if you don't need it anymore.
     
  16. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,846
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    that is veeery vague question, elaborate.

    Because you can look from multiple angels at this question. Obviously they leak if you dont destroy them when you are done with them, for instance
     
  17. plumsy460

    plumsy460

    Joined:
    Oct 2, 2013
    Messages:
    272
    Resources:
    0
    Resources:
    0
    So using Center of Region does leak a point?
    Unless it is being reused or what?
     
  18. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,182
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Like Ralle explained in his example, you have to use a point variable and then you can prevent the leak:

    Set loc = Centre Of Rect <A>
    Unit - Create 1 unit at loc
    Custom script: call RemoveLocation(udg_loc)
     
  19. plumsy460

    plumsy460

    Joined:
    Oct 2, 2013
    Messages:
    272
    Resources:
    0
    Resources:
    0
    I see. If I reuse that location variable "loc" (without changing location), do I still need to remove it to prevent leak?
     
  20. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,846
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    you have to do the custom script, but you can reuse the variable.

    This is because the variable is like a finger, and it merely points at the real object(this is called pointer in programming, but it is not begginer-friendly thing)