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. The 15th Mini-Mapping Contest came to an end. The Secrets of Warcraft 3 are soon to be revealed! Come and vote in the public poll for your favorite maps.
    Dismiss Notice
  3. The 12th incarnation of the Music Contest is LIVE! The theme is Synthwave. Knight Rider needs a song to listen to on his journey. You should definitely have some fun with this theme!
    Dismiss Notice
  4. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    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. nedio95

    nedio95

    Joined:
    Mar 24, 2011
    Messages:
    1,055
    Resources:
    1
    Spells:
    1
    Resources:
    1
    I don't like garbage collectors. I like handling my own memory. (or somebody else's memory)

    regards
    -Ned
     
  2. Abishkar

    Abishkar

    Joined:
    Dec 17, 2017
    Messages:
    124
    Resources:
    0
    Resources:
    0
    Well, I am creating a map where waves of units will be spawned from a same particular point and ordered to move to a region. Do I have to call every time with the custom script? Can someone show me how to do it
     
  3. nedio95

    nedio95

    Joined:
    Mar 24, 2011
    Messages:
    1,055
    Resources:
    1
    Spells:
    1
    Resources:
    1
    @Abishkar
    • Events
      • Time - Every 1.0 sek of game time
    • Conditions
    • Actions
      • Set TempPoint = Center of region <gg_Sapwn_Region_0001>
      • Unit - Create 1 footman at TempPoint for player 1(red) facing 0.00 degree
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Set TempPoint = Centre of region <gg_Attack_Here_Region_0002>
      • Unit - Order (Last Created Unit) to Attack-Move TempPoint
      • Custom script: call RemoveLocation(udg_TempPoint)


    Like this?
    Have in mind, I just typed this in the web browser.
    Syntax may not accurately reflect WE equivalents ;)

    Note that "TempPoint" and "udg_TempPoint" are exactly the same thing.
    First one would be it's name in GUI and the second would be for JASS.
    udg = User Defined Global, those are the variables that you create with the variable editor.

    //Edit: If you require any further help, I'd suggest opening your own thread around

    regards
    -Ned
     
    Last edited: Jun 15, 2018
  4. Abishkar

    Abishkar

    Joined:
    Dec 17, 2017
    Messages:
    124
    Resources:
    0
    Resources:
    0
    Holy damn, do I have to call after each? Then it will be such a pain in the ass.
    I mean like this, a footman is spawned from Region A and ordered to move to Region B. Then, a knight is spawned from the same Region A and ordered to move to Region B. So, will I call after The footman spawn and again call after the Knight spawn? Or do I have to call after all the units have spawned? @nedio95
    P. S. : Love how you write "Regards - Ned" in the end of every message. Ha ha :)
     
  5. nedio95

    nedio95

    Joined:
    Mar 24, 2011
    Messages:
    1,055
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Every time you need to use a point.

    If you are going to re-use a point you could not de-allocate it.
    E.g.
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set SpawnPoint[0] = Centre of SpawnRegion1
      • Set SpawnPoint[1] = Centre of SpawnRegion2
      • Set AttackPoint[0] = Centre of AttackRegion1
      • Set AttackPoint[1] = Centre of AttackRegion2


    • Events
      • Time - Every 1.0 sek of game time
    • Conditions
    • Actions
      • For Loop integer temp_Index from 0 to 1
        • Loop
          • Unit - Create 1 footman at SpawnPoint[temp_Index] for player 1(red) facing 0.00 degree
          • Unit - Order (Last Created Unit) to Attack-Move AttackPoint[1]


    If your regions are not used for anything else, this may be a better approach.

    PS: regards
    -Ned
     
  6. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    896
    Resources:
    1
    Maps:
    1
    Resources:
    1
    does making group in conditions also leak?

    E.g.

    • (Number of living Grunt units owned by Player 1 (Red)) Less than 4
     
  7. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,573
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
  8. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    896
    Resources:
    1
    Maps:
    1
    Resources:
    1
    so the best way to go about it is to put in actions
    set groupTemp

    and then do an If Else Function?
     
  9. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,573
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    The only way in GUI, yes. JASS does not have the same problem ;p
     
  10. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,255
    Resources:
    6
    Models:
    1
    Icons:
    1
    Spells:
    3
    JASS:
    1
    Resources:
    6
    I would say that creating conditions in GUI is technically not a leak, but the group itself does if used momentarily, and it is not destroyed.

    The method above is the recommended way of filtering out the desired units, and I think it is one out of two ways of filtering them out.
     
  11. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    896
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Lets have a look at this little trigger.

    • Hard Extra Defense
      • Events
      • Conditions
      • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of living Grunt units owned by Player 1 (Red)) Less than 4
      • (Number of living Barracks units owned by Player 1 (Red)) Greater than 0
    • Then - Actions


    Now to fix the leaking trigger above, I will write it like this:
    • Hard Extra Defense
      • Events
      • Conditions
      • Actions
        • Set GroupTemp01 = (Units owned by Player 1 (Red) matching (((Matching unit) is alive) Equal to True))
        • Set GroupTemp02 = (Units owned by Player 1 (Red) matching (((Matching unit) is alive) Equal to True))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Number of units in GroupTemp01) Less than 4
            • (Number of units in GroupTemp02) Greater than 0
          • Then - Actions
        • Custom script: call DestroyGroup(udg_GroupTemp01)
        • Custom script: call DestroyGroup(udg_GroupTemp02)


    is that it? or what I did was totally unnecessary anyway?

    @MyPad Post confused me o_O
    so it leaks or not?
     
  12. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,255
    Resources:
    6
    Models:
    1
    Icons:
    1
    Spells:
    3
    JASS:
    1
    Resources:
    6
    The first example will leak. However, the second will not leak objects, since you destroy the group handles.

    Condition or no condition, creating a group means that you have to have the responsibility of destroying it.

    Extra

    If you'd like to get more technical, there is a bug that causes the handle stack to permanently increase, despite the successful elimination of handle objects (in this case, groups). It presents itself when a locally declared variable is passed as a return value in a function. Notwithstanding, the functions in GUI about unit groups all return the locally declared group handle.

    It was present before, and might still be present now.
     
  13. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,527
    Resources:
    0
    Resources:
    0
    @map designer you can also automatically clean the group leak by doing Custom script: set bj_wantDestroyGroup = true right before the line that creates the group. That line tells the game to automatically destroy the next group it makes once it's done with it.

    Unfortunately that will not work when you have 2 different groups created in the same if-block, since you can't put CS lines in there in GUI. It will work for just one, though. Also don't will-nilly set that variable unless you know FOR SURE you are about to create a group, since setting it and not making a group would cause the game to destroy whichever group it next makes, likely in a totally unrelated trigger.
     
  14. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    896
    Resources:
    1
    Maps:
    1
    Resources:
    1
    hmmmm

    I thought that dynamic function will automatically destroy any group created by this trigger at the end of this trigger.

    this raised the question for me though: when does this function destroy the group? at the end of this trigger? or when? if it was destroyed pre-maturely it would miss up the trigger wouldnt it?
     
  15. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,527
    Resources:
    0
    Resources:
    0
    Every unit group action uses ForGroupBJ() internally. The destroy happens right at the end of the function call:
    Code (vJASS):
    function ForGroupBJ takes group whichGroup, code callback returns nothing
       // If the user wants the group destroyed, remember that fact and clear
       // the flag, in case it is used again in the callback.
       local boolean wantDestroy = bj_wantDestroyGroup
       set bj_wantDestroyGroup = false

       call ForGroup(whichGroup, callback)

       // If the user wants the group destroyed, do so now.
       if (wantDestroy) then
           call DestroyGroup(whichGroup)
       endif
    endfunction


    The way it stores the value of bj_wantDestroyGroup locally before calling ForGroup() itself allows you to nest group picks and they'll all be properly destroyed:

    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in...
      • Loop - Actions
        • Custom script: set bj_wantDestroyGroup = true
        • Unit Group - Pick every unit in...
          • Loop - Actions
            • Custom script: set bj_wantDestroyGroup = true
            • Unit Group - Pick every unit in...
              • Loop - Actions
                • -------- ad infinitum --------
     
  16. JC Helas

    JC Helas

    Joined:
    Oct 19, 2014
    Messages:
    154
    Resources:
    2
    Spells:
    2
    Resources:
    2
    Sir can I use same key in each variable types in hashing to one parent and table?
     
  17. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,943
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I highly discourage that. I recommend only storing one variable per parent/child key combination. If there is any data to show what I'm saying can be disregarded (ie. if they have done any tests) feel free to show me up here.
     
  18. JC Helas

    JC Helas

    Joined:
    Oct 19, 2014
    Messages:
    154
    Resources:
    2
    Spells:
    2
    Resources:
    2
    what I mean sir is,, I thought key is like an array of a variable isnt it?
     
  19. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,943
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    There's a parent key, and a child key. Each parent represents an address which can store child keys with indices as high as integers allow.

    So really, each parent key is a single array with "unlimited" slots but one which doesn't need to initialize all previous array indices in between slots. That's the difference between a hash table and an array.

    So really I just want to make sure we're on the same page, cause you're not making too much sense so far.
     
  20. DracoL1ch

    DracoL1ch

    Joined:
    Dec 12, 2010
    Messages:
    1,751
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    actually you'd better reduce amount of parents to lowest possible, thats overheat right there. Better to have Save*(HT,0,spellid,callback) rather than Save*(HT,spellid,0,callback)