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. Join the 6th Melee Mapping Contest for a chance to have your map featured in this year's Hive Cup!
    Dismiss Notice
  4. Sate your hunger with the 33rd Modeling Contest!
    Dismiss Notice
  5. Do you hear boss music? It's the 17th Mini Mapping Contest!
    Dismiss Notice
  6. Let your favorite entries duke it out in the 15th Techtree Contest Poll.
    Dismiss Notice
  7. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  8. 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. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,515
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Not sure, but yeh I think they're null terminated, at least it's most likely they're also normal c++ strings.

    That nullAsString() didn't work for concatenation as first parameter with +operator...: param1 + param2 ... makes me think it doesn't return any valid string, also not "\0". So tying to call the c++ concat from jass vm will not work correctly.
    And that nullAsString() is accepted as second param is maybe only because of extra vm checks, before calling the c++ concat.
    But... hey, it's just my theory, maybe it's simply wrong, too. :D
     
  2. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,147
    Resources:
    38
    Models:
    15
    Icons:
    16
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    38
    hehe, well guessing is the best we can do without any official documentation xD
     
  3. Mightylink

    Mightylink

    Joined:
    Aug 4, 2019
    Messages:
    4
    Resources:
    0
    Resources:
    0
    Thank you for creating this thread, I added it to my notes of things to do whenever I create a trigger, you're breathtaking! :D
     
  4. Map Designer

    Map Designer

    Joined:
    May 2, 2011
    Messages:
    1,156
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    does string variable leak when used multiple times?

    but if doesnt leak twice then it is not leak right? because each variable will take memory once anyway; the problem with leaks is that they take more and more memory if not destroyed/cleared.
     
  5. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,515
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    This thread covers very much information: [Documentation] String Type

    What is meant is that a when a string is used for the first time, for example "Hello", then this will take up memory, and it gets written into a string table. This entry from string table will never be removed.
    But also, from then on, when ever you use "Hello" again, it will use this same entry from the string table.

    But what might be important is that it's talking about JASS, not Lua.
     
  6. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,147
    Resources:
    38
    Models:
    15
    Icons:
    16
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    38
    If it happens whatever you do, and you can't remove it from the string table, then I wouldn't really call it a leak.
     
  7. Map Designer

    Map Designer

    Joined:
    May 2, 2011
    Messages:
    1,156
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    why? if something uses unwanted memory its a leak, whether this leak can be removed or not is another story.


    @IcemanBo Paladin and then pal or paladin01 will use 3 different locations in string table right?
     
  8. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,147
    Resources:
    38
    Models:
    15
    Icons:
    16
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    38
    Well, it seems to be by design. The string is stored permanently for later reuse. Whether it's a good design is up for debate and depends on the use-case, but I wouldn't say it's a leak. A leak is when memory becomes unreadable and unwriteable unless you do garbage collection, IMO. In this case, the memory is still accessible and the data stored is still useful as long as you use the same string again.
     
  9. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,515
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Yes and it's explained in the linked thread.
     
  10. Map Designer

    Map Designer

    Joined:
    May 2, 2011
    Messages:
    1,156
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    I have 2 Qs

    First, the Custom script: set bj_wantDestroyGroup = true is global variable right? so I only need to use it in map initialization and not have to use it in each trigger in my map right?

    2nd
    it seems to me that Custom script: call RemoveLocation(udg_loc) and the Custom script: call DestroyGroup(udg_GroupVar)
    are better used just before setting up the group so that the old one is deleted. no?
     
  11. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,147
    Resources:
    38
    Models:
    15
    Icons:
    16
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    38
    AFAIK there's no reason to use that variable at all (bj_wantDestroyGroup). It's something that's used in BJ functions.

    RemoveLocation/DestroyGroup should be used on any location/group that isn't used anymore. So yes, definitely do it before reassigning the variable.
     
  12. Map Designer

    Map Designer

    Joined:
    May 2, 2011
    Messages:
    1,156
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    in most practices I saw it done the other way around. everything is removed at the end of trigger that used it, and not at the beginning of trigger that will use it.
     
  13. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,147
    Resources:
    38
    Models:
    15
    Icons:
    16
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    38
    Well yeah, what I mean is, if you have a unit group variable which is assigned a unit group, you should destroy that unit group before assigning a different unit group to that variable.
    Basically it should be destroyed once its not used anymore, regardless of what you do with the variable afterward.
    Usually this is at the end of a trigger/function, but in some cases it may be at different places.
     
  14. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,515
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    bj_wantDestroyGroup
    is a global and will be reset to false in the GUI/BJ functions. So it would not be enough to set it to
    true
    only once.
    The other one is a design question, but most common practice is to clear things when their job is done, instead of requiring others to clean things before they start.
     
  15. Map Designer

    Map Designer

    Joined:
    May 2, 2011
    Messages:
    1,156
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    hmmm,

    I was thinking there was a chance that the same group might be used by another trigger, but maybe you are right.
     
  16. Map Designer

    Map Designer

    Joined:
    May 2, 2011
    Messages:
    1,156
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    at least it will be enough once in each trigger right? so If I have a loop that will use the same location variable 100 times, it is enough to use the custom script once and it will not leak? I mean Custom script: set bj_wantDestroyGroup = true

    Edit: wait I don't see in OP equivalent of WantDestroyLocation = true; such thing doesnt exist?
     
  17. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,147
    Resources:
    38
    Models:
    15
    Icons:
    16
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    38
    You should not rely on any bj_wantDestroyX (not sure if any exist beside the one for Group). It's best to just `call DestroyGroup(group)` manually.
     
  18. TheFireMage

    TheFireMage

    Joined:
    Jul 23, 2018
    Messages:
    106
    Resources:
    0
    Resources:
    0
    Will it leak if I use a region variable?
     
  19. Map Designer

    Map Designer

    Joined:
    May 2, 2011
    Messages:
    1,156
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    this
     
  20. TheFireMage

    TheFireMage

    Joined:
    Jul 23, 2018
    Messages:
    106
    Resources:
    0
    Resources:
    0