1. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  2. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  3. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  4. Check out the Staff job openings thread.
    Dismiss Notice

Things That Leak

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

  1. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    893
    Resources:
    1
    Maps:
    1
    Resources:
    1
    sorry,

    I meant if I saved the 2 points in a variable already, I will destroy these two points later. again, what was the 3rd thing that would leak?


    so, here is the trigger

    • IncenerationCast
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Channel (Trigger Spell)
      • Actions
        • Quest - Display to (All players) the Quest Update message: SPELL HAS BEEN CAST
        • Set Temp_target1 = (Target unit of ability being cast)
        • Set Temp_Point1 = (Position of (Triggering unit))
        • Set Temp_Point2 = (Position of Temp_target1)
        • Unit - Create 1 Acid (Caster) for Player 1 (Red) at Temp_Point1 facing (Angle from Temp_Point1 to Temp_Point2) degrees
        • Set Temp_Caster2 = (Last created unit)
        • Unit - Order Temp_Caster2 to Neutral Alchemist - Acid Bomb Temp_target1
        • Unit - Create 1 Fire Trigger (Caster) for Player 1 (Red) at Temp_Point1 facing (Angle from Temp_Point1 to Temp_Point2) degrees
        • Set Temp_Caster1 = (Last created unit)
        • Unit - Order Temp_Caster1 to Night Elf Warden - Shadow Strike Temp_target1
        • Unit - Remove Temp_Caster2 from the game
        • Custom script: call RemoveLocation(udg_Temp_Point1)
        • Custom script: call RemoveLocation(udg_Temp_Point2)
     
    Last edited: May 3, 2019
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    It's correct that you don't leak if you store the both locations into variables and remove them after usage. A third location or something else isn't used that could leak, here's the code behind:
    Code (vJASS):
    function AngleBetweenPoints takes location locA, location locB returns real
        return bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))
    endfunction


    No, not really. It's just operations in the end, like 1+1, no object is created. For some background in general Memory Leaks.
     
  3. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    893
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Does this mean my code is just fine? or is it better if I stored the angle in a variable Temp_angle? (I did update the trigger just now since I forgot to remove Caster2)
     
    Last edited: May 3, 2019
  4. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    It is just fine as it is.
    Keep in mind, to make the calculation, you make a function call, and some maths operation. If you need this angle multiple times, then you might use a temp variable. It's basically also easier to read good variable names in code than reading all functions somewhere in between. But still, this has nothing todo with a leak.
     
  5. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    893
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Thanks!

    the 3rd thing that would leak still bugs me though. what was that extra thing which would leak Had I not saved these variables?
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    As said there is no third leak. It was simply a mistake.
    Very welcome!
     
  7. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Uhm, quick question, do texttags (floating text) need to be destroyed when they are set to not be permanent (
    SetTextTagPermanent
    )?
    The GUI trigger comment seems to imply that they're cleaned up automatically.

    If so, I guess you need to use a sleepaction or timer to do it :(
     
  8. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    If they're removed via the lifespan if shouldn't leak.
     
  9. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Ah, great, thanks.
     
  10. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    893
    Resources:
    1
    Maps:
    1
    Resources:
    1
    does pick every destructible function leak?

    what about kill random destructible in region?

    if it leaks, how do I make destructible group and destroy it?
     
    Last edited: May 21, 2019
  11. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Enumerating destructables does not create something like a destructable group that could leak. You're safe here.

    And as long you don't create a new region/rect for "Pick All Destructable in <Region>" there's no rect leak, too.
     
  12. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    893
    Resources:
    1
    Maps:
    1
    Resources:
    1
    and if we pick all in region, then we have to destroy it dynamically?
     
  13. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    The region should be destroyed unless it's one that you've created with the editor.

    This is fine:
    • Destructible - Pick every destructible in MyRegion <gen> and do (Destructible - Kill (Picked destructible))


    This leaks a region:
    • Destructible - Pick every destructible in (Region(0.00, 0.00, 0.00, 0.00)) and do (Destructible - Kill (Picked destructible))


    Can be fixed like this:
    • Custom script: set udg_TempRegion = Rect(0, 0, 0, 0)
    • Destructible - Pick every destructible in TempRegion and do (Destructible - Kill (Picked destructible))
    • Custom script: call RemoveRect(udg_TempRegion)
    • Set TempRegion = No region
     
    Last edited: May 21, 2019
  14. map designer

    map designer

    Joined:
    May 2, 2011
    Messages:
    893
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Hello

    If I use dynamic destruction of Unit Group, Could it destroy my group at the end of each trigger? or does it destroy the group when it is assigned another value?

    the first case can be a problem because it might destroy my group too early
     
  15. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
  16. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Code (vJASS):

    local unit u

    loop
        set u = FirstOfGroup(grp)
        exitwhen u == null
        call GroupRemoveUnit(grp, u)
    endloop
     


    Does the above code still leak a reference if we don't
    set u = null
    after the loop? I.e. is null still considered a reference if it's actually a null agent and not a plain null? Not sure if I explained that well.
     
  17. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    No it's no leak, null == null.
    null is also only a part in memory, but a special one for default. One does not have any rights to write in this memory, one only can read it. So always when a function should return some object for example, but can't return any valid object for what ever reason (for example there is no FirstOfGroup() anymore), it can use the return null possibility (and should do). So just always when "null" is returned it does mean the function can't return valid values, and there's no further steps in difference of "null". In the end it's only important the agents point on some other memory not equal the object's memory it pointed to, and null is such other part in memory.
     
  18. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Great, thanks!

    I asked because I think I saw somewhere (don't remember where) that a null string isn't necessarily the same as null when returning/concatenating (or something).
    So I assume this just means that "" (empty string) is of type string, but null is not of type string?
     
  19. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    It's not very the same, yes.

    When you have "" as string, it is a true string object. It has no chars in it, but you can do everything you want with it, like you can with any other strings. It can call functionality.
    When you try to work with null, the string functionality can't be used. It's no real object, so concatenating (which is just a function in some way for the string object) isn't working.

    But also some test cases:

    case 1:
    set s = null + "text"
    -> compiler error. (expected)

    Next, this is more or less, too, as expected, case 2:
    Code (vJASS):

    function nullAsString takes nothing returns string
        local string s // just for no inline
        return null
    endfunction

    local string s = nullAsString() + "test"
    -> sums up to (null) , no valid string.

    case 3 ..
    local string s = "test" + nullAsString()
    -> prints "test"
    (at least from my theory above this is a bit unexpected)

    And also, case 4:
    Code (vJASS):

    local string s = null
    set s = s + "test"
    -> printes "test"
    (might be unexpected like case 3, because null can not have functionality)

    ===

    Both last cases would not work in normal c++, for example.

    One might argue case3 works over case2 because the first string is actually always the string which actually calls the functionality, so the concatenate function, and so it is valid. First string is the calling object. And then there are internal checks for the second parameter, if the string to add is null, which will result in like adding an empty string/just nothing.

    Case 4, there is maybe some implicit string conversion directly done here, when assining null to a string variable,
    local string s = null
    . So from then it's simply seen as empty string "".

    ===

    So when having a conrete string variable, set to null, it may act as "", while working directly with null doesn't work with string concatenation.
    Working with functions that return null (without being stored into a string variable) does not work for calling string concatenation as first parameter, but it will not cause an invalid string, when given as second parameter.

    Basically as long as the string is only input for some function that jass vm controls, and is not the calling object itself like in string concatenation, null seems always be reacted same like empty string "". It's most likely some jass comfort that it is like this, checking for null at many places to keep nicer usage.
     
    Last edited: May 29, 2019
  20. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    I see, interesting. Is it possible JASS strings are null-terminated? So nullAsString actually returns something like "\0" ? Dunno, don't know much about the internal workings of these things, though I have experience with C++.