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. Ride into the sunset with the 32nd Modeling Contest. The contest is optionally paired. Best of luck, people!
    Dismiss Notice
  4. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  5. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  6. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  7. 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.

Memory Leaks

Discussion in 'Trigger (GUI) Editor Tutorials' started by IcemanBo, Mar 6, 2015.

  1. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,275
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Added minimal paragraph about the enum type. Thanks for list to Aniki.
     
  2. Michael the Boombringer

    Michael the Boombringer

    Joined:
    Dec 18, 2016
    Messages:
    101
    Resources:
    0
    Resources:
    0
    There are actually two ways of removing leaks:
    1) Has just been presented to you;
    2) convincing blizzard to improve JASS.
     
  3. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,275
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    If JASS decreased local ref counter automaticaly it won't (could not) do it for your global scope if objects aren't destroyed, so you still have to care.
    And in any case maybe it's good to know that one should remove his data once it's not used anymore! ^)^
     
  4. Michael the Boombringer

    Michael the Boombringer

    Joined:
    Dec 18, 2016
    Messages:
    101
    Resources:
    0
    Resources:
    0
    Is there anything that checks leaks?
     
  5. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,275
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
  6. Michael the Boombringer

    Michael the Boombringer

    Joined:
    Dec 18, 2016
    Messages:
    101
    Resources:
    0
    Resources:
    0
  7. CampScouter

    CampScouter

    Joined:
    Apr 13, 2017
    Messages:
    157
    Resources:
    0
    Resources:
    0
  8. Aniki

    Aniki

    Joined:
    Nov 7, 2014
    Messages:
    524
    Resources:
    4
    Spells:
    1
    JASS:
    3
    Resources:
    4
    From tinkering with the handle table, I think it's entries have a single field for storing the reference count of a handle, that is set to 1 upon the creation of the handle, and it gets modified by assignments to variables (global and local, scalar and arrays) and saving/removing the handle from a hashtables, so it seems to me that the section "Difference between local and global" is a bit off?
     
  9. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,275
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    You say there is no difference, or I didn't understand it right?
     
  10. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,367
    Resources:
    7
    Models:
    1
    Icons:
    2
    Spells:
    3
    JASS:
    1
    Resources:
    7
    ^^ I think that @Aniki is saying that the locals and the globals are described on how they behave when dealing with references, and not their primary context, hence the confusion.
     
  11. lavagamer_agar.io

    lavagamer_agar.io

    Joined:
    Feb 7, 2016
    Messages:
    22
    Resources:
    0
    Resources:
    0
    what is the variable type i must use in the create unit at point leaks?
     
  12. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,367
    Resources:
    7
    Models:
    1
    Icons:
    2
    Spells:
    3
    JASS:
    1
    Resources:
    7
    type location extends agent


    call RemoveLocation(<loc>)
     
  13. lavagamer_agar.io

    lavagamer_agar.io

    Joined:
    Feb 7, 2016
    Messages:
    22
    Resources:
    0
    Resources:
    0
    ty for the help
     
  14. Thendar

    Thendar

    Joined:
    May 12, 2017
    Messages:
    34
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Im currently trying to do everything do debug my map and I was asking myself: How many leaks can my map have to assure that nobody gets disconnected etc. I know it depends on more but lets say a classical td without anything around it, so no big deal at its self. I know my map has some issues with leaks and Im not sure if Im skilled enought to remove all of them, thats why Im asking
     
  15. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,275
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Updated.
    Most changes are "Data Types", "Reference Leaks", and to shorten everything.
     
  16. Devalut

    Devalut

    Joined:
    Feb 9, 2009
    Messages:
    1,162
    Resources:
    2
    Spells:
    2
    Resources:
    2
  17. Strydhaizer

    Strydhaizer

    Joined:
    Feb 28, 2013
    Messages:
    1,766
    Resources:
    4
    Models:
    1
    Maps:
    1
    Template:
    2
    Resources:
    4
    As far as I know sound destroys itself after playing.

    By the way up to this day I'm still curious if Destructible Groups can leak.
     
  18. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,275
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Sounds can leak. Though, JASS is needed to really create new sounds, which happens automatically in background only once, when used in GUI. So one is safe in GUI.

    There's no leak like this. There's nothing like a destructible group for storage, but only the mere enumeration of destructibles.
     
  19. Strydhaizer

    Strydhaizer

    Joined:
    Feb 28, 2013
    Messages:
    1,766
    Resources:
    4
    Models:
    1
    Maps:
    1
    Template:
    2
    Resources:
    4
    Hello IcemanBo, I'm just curious (again) does this function actually leak?

    • Unit Group - Pick all units of type Footman and do


    Should I really keep away from using this function? Or is this similar to picking all units in the map and adding condition to only get Footman units?

    It is mentioned here (Things That Leak) not to use this function but this wasn't mentioned/missing at the main post, or did I just miss it?
     
  20. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,275
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    The JASS behind needs to be compared for it:
    PickAllUnitsOfType
    Code (vJASS):
    function GetUnitsOfTypeIdAll takes integer unitid returns group
        local group   result = CreateGroup()
        local group   g      = CreateGroup()
        local integer index

        set index = 0
        loop
            set bj_groupEnumTypeId = unitid
            call GroupClear(g)
            call GroupEnumUnitsOfPlayer(g, Player(index), filterGetUnitsOfTypeIdAll)
            call GroupAddGroup(g, result)

            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call DestroyGroup(g)

        return result
    endfunction
    ^it has no object leak inside, but 2 reference leaks.

    PickAllUnitsInRect
    Code (vJASS):
    function GetUnitsInRectMatching takes rect r, boolexpr filter returns group
        local group g = CreateGroup()
        call GroupEnumUnitsInRect(g, r, filter)
        call DestroyBoolExpr(filter)
        return g
    endfunction
    ^this has 1 reference leak.

    So the "PickAllUnitsOfType" has one more reference leak.
    Of course it's not good to have more reference leaks, but imo it's not critical. Finally you won't avoid them anyways in GUI, and people used it for ever and without problems.
    Lua mode would not have the problem with reference leaks at all btw, as it's fixed there by its nature already... in case it matters for you.

    As there are so many GUI functions with reference leaks included I decided not to give some a special platform, even 2 of ref leaks are included, and just mentioned: