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 poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  4. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  5. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  6. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  7. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    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. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Good info there to add for him. Though I still would like to know what he's talking about.
     
  2. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,033
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    At least handles are not disjunct. There is still the return bug substitute floating around where you can store an integer as fogstate and load it as another handle type. There is also the RemoveSavedHandle native, which hints at that. But often, you can limit yourself to storing integer indexes in hashtables and then use them in arrays. Or you could just use multiple hashtables.

    How so?

    JC Helas asked if e.g. SaveInteger(table1, parentKey1, key1, <integer>) and SaveUnitHandle(table2, parentKey2, key2, <unit>) where table1==table2, parentKey1==parentKey2, key1==key2 is viable, probably if they are disjunct as I responded to.
     
    Last edited: Nov 10, 2018
  3. DracoL1ch

    DracoL1ch

    Joined:
    Dec 12, 2010
    Messages:
    1,757
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Maybe technicall they are identical in terms of storage usage, but remember one patch where blizzard broke hashtables by limiting parents count to 1024 or so? Within engine parents are being counted and stored, RemoveSavedX doesn't deduct parent counter, FlushChildHashtable() does although. I dont know where this counter is used and what purpose he serves, but why would you increase this counter with no good reason to? Thats my logic.
     
  4. JC Helas

    JC Helas

    Joined:
    Oct 19, 2014
    Messages:
    155
    Resources:
    2
    Spells:
    2
    Resources:
    2
    What if I will do this way

    unit u = dummy
    integer i = 1
    real r = 1.00
    integer id = GetHandleId(u)
    SaveInteger(table,id,0,i)
    SaveReal(table,id,0,r)

    look I use 0 key in different native. is this leak?
     
  5. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,033
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    Never heard of it. I have no insight of the internals. When you say there's a counter, that seems marginal in terms of performance. My idea is to discriminate it by the FlushChildHashtable function, children are mapped to a parent, and this function makes it easy to erase everything in one swoop. Is the limit still in existence?
     
  6. DracoL1ch

    DracoL1ch

    Joined:
    Dec 12, 2010
    Messages:
    1,757
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    the counter itself means nothing, but as I said there might be inner stuff bound to it. HT is already linked list, MAYBE this counter used for something else what matter, maybe not. This arg swap costs 0 time for mapmaker so should be respected as long as it fits codestyle
     
  7. DracoL1ch

    DracoL1ch

    Joined:
    Dec 12, 2010
    Messages:
    1,757
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    read documentary, hashtable can save 1 type per every cell, int/real/bool/handle/string, no problems. only handles can leak of those
     
  8. Gottfrei

    Gottfrei

    Joined:
    Jan 16, 2009
    Messages:
    84
    Resources:
    20
    Models:
    19
    Icons:
    1
    Resources:
    20
    hey, guys. need to know is this function leaks "uC" cause i'm not nullifying it?

    Code (vJASS):

    function GroupGetClosestUnit takes unit whichUnit, group whichGroup returns unit
        local integer i = 0
        local unit u = FirstOfGroup(whichGroup)
        local unit uC
        local unit array uG
        local real x = GetUnitX(whichUnit)
        local real y = GetUnitY(whichUnit)
        local real xT = GetUnitX(u)
        local real yT = GetUnitY(u)
        local real dist
        local real distC = SquareRoot((x - xT) * (x - xT) + (y - yT) * (y - yT))
        loop
            set u = FirstOfGroup(whichGroup)
            exitwhen u == null
            set xT = GetUnitX(u)
            set yT = GetUnitY(u)
            set dist = SquareRoot((x - xT) * (x - xT) + (y - yT) * (y - yT))
            if dist < distC then
                set uC = u
            endif
            set uG[i] = u
            set i = i + 1
            call GroupRemoveUnit(whichGroup, u)
        endloop
        loop
            exitwhen i < 0
            call GroupAddUnit(whichGroup, uG[i])
            set uG[i] = null
            set i = i - 1
        endloop
        set u = null
        return uC
    endfunction
     
     
  9. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,475
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Yes it causes the handle index referenced by uC at the time of return to have a leaked reference count and hence when that unit is removed the handle index assigned to it cannot ever be recycled.

    Solution is to use either a function parameter or a global variable to temporarily hold the value while the local is nulled and then return the value.
     
  10. Gottfrei

    Gottfrei

    Joined:
    Jan 16, 2009
    Messages:
    84
    Resources:
    20
    Models:
    19
    Icons:
    1
    Resources:
    20
    so now its basically fixed? i can simply make uTemp parameter equal to "null".
    Code (vJASS):

    function GroupGetClosestUnit takes unit whichUnit, group whichGroup, unit uTemp returns unit
        local integer i = 0
        local unit u
        local unit uC = FirstOfGroup(whichGroup)
        local unit array uG
        local real x = GetUnitX(whichUnit)
        local real y = GetUnitY(whichUnit)
        local real xT = GetUnitX(uC)
        local real yT = GetUnitY(uC)
        local real dist
        local real distC = SquareRoot((x - xT) * (x - xT) + (y - yT) * (y - yT))
        loop
            set u = FirstOfGroup(whichGroup)
            exitwhen u == null
            set xT = GetUnitX(u)
            set yT = GetUnitY(u)
            set dist = SquareRoot((x - xT) * (x - xT) + (y - yT) * (y - yT))
            if dist < distC then
                set uC = u
            endif
            set uG[i] = u
            set i = i + 1
            call GroupRemoveUnit(whichGroup, u)
        endloop
        loop
            exitwhen i < 0
            call GroupAddUnit(whichGroup, uG[i])
            set uG[i] = null
            set i = i - 1
        endloop
        set uTemp = uC
        set u = null
        set uC = null
        return uTemp
    endfunction
     
     
  11. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,165
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Not sure the extra parameter would be worth the ref leak, but yes, you're correct.
     
  12. Gottfrei

    Gottfrei

    Joined:
    Jan 16, 2009
    Messages:
    84
    Resources:
    20
    Models:
    19
    Icons:
    1
    Resources:
    20
    and what would be better? global variable solution?
     
  13. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,165
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    You for sure can use it like this, I just would personally not like to give an extra parameter for counter a ref leak. As usage seems becomes worse.

    Using a global would be maybe nicer, as it would change nothing for code usage. Some use Blizzard globals like
    bj_lastCreatedUnit
    , but using a seperated variable is better, as it can't come unwilligly in conflict with other's code. (if some GUI user in the example would ever work with "last created unit")

    But that's also not really a "perfect" solution maybe. You also might to consider risking the leak, if you're too lazy for the global. ^^
     
  14. Gottfrei

    Gottfrei

    Joined:
    Jan 16, 2009
    Messages:
    84
    Resources:
    20
    Models:
    19
    Icons:
    1
    Resources:
    20
    duh. this jass is killing me.
     
  15. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,475
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Use a global variable. Hopefully with reforged this leak finally gets fixed but for now I strongly advise explicitly fixing them to avoid issues in the meantime.
     
  16. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    896
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Hello,
    this conition for trigger will leak right?
    Event-
    Unit owned by player 11 dies.
    Conditions -
    (Number of units in (Units owned by Player 11 (Dark Green))) Equal to 0

    what about this condition
    (Count structures controlled by Player 12 (Brown) (Exclude incomplete structures)) Equal to 0


    and to fix it, I better move this condition into an if statement right? i.e. set Q equal number of units owned by etc
     
    Last edited: Apr 7, 2019
  17. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,165
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Yes, in detail, "(Units owned by Player 11 (Dark Green))" does create a unit group.

    And also yes, to prevent the leak in GUI you need to move this condition into the actions-block, and destroy the group as usual, with help of a variable.
     
  18. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,475
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Yes it leaks a group and even if that leak were fixed it will leak a handle ID.
    To fix the group leak you need to do what IcemanBo describes and move the test into an if block in the actions. This allows one to assign a unit group variable before performing the test and use DestroyGroup on it after the test.

    Fixing the handle ID leak is harder. Requiring either a custom script call to a fixed version of "Units owned by" function or importing a fixed blizzard.j file. Importing a fixed blizzard.j file is not recommended as it might negatively effect a maps forwards compatibility with future versions of Warcraft III if Blizzard changes anything in that file.
    This does not leak as far as I can tell.
     
  19. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    896
    Resources:
    1
    Maps:
    1
    Resources:
    1
    is (angle between 2 points) leaking?

    or in general, does any arithmetic operation leak if they are not stored into a variable which then will be destroyed?
     
  20. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    That leaks 3 locations. Check the "Triggering tips" link in my signature for more information.