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. blancfaye7

    blancfaye7

    Joined:
    May 21, 2014
    Messages:
    560
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Well...! My map does this.

    I'm always pointing to permanent unit leaks. My triggers don't cause leaks (as rechecked by other people too; except for the permanent and once per game leaks.)

    Bah! I guess I need to calculate if it's really them.
     
  2. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,428
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    If the map is big enough/has enough "stuff", it might freeze for a bit anyway. It just happens in general when a map has used a lot of memory.

    Just be sure to check your triggers for leaks and you'll be fine.
     
  3. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,272
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Back then I remember when we played our beloved ice escape maps we had a black screen for several or more minutes. (depending on game time)
    After 1 year or so we found it is because of memory leaks and removed them.
    Though during this "leak-time" the map was somehow still playable pretty well, even after long sessions. Idk how.

    If your screen freezes for a few seconds for 1 hour of playing, I don't think it is a real problem.
    And as PnF said, it also might be of normal map's memory consumption. :)
     
  4. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,846
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    the most likely cause of this is that wc3 starts to deallocate all the memory that the game allocated during that map, and if you have to deallocate chuncks of like 20 bytes, but overall 400 MB, it takes extremly long(in comparision, calling destructor of std::vector<int> in C++, which deallocates the memory) with like couple dozens of milions of integers will take like few seconds too, and that is one giant contiguous array, it isnt split among many many places)
     
  5. blancfaye7

    blancfaye7

    Joined:
    May 21, 2014
    Messages:
    560
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Just what I wanted to know and hear... thanks guys.

    Nice updates since I last visited last year though. Keep it up!
     
  6. KILLCIDE

    KILLCIDE

    Administrator

    Joined:
    Jul 22, 2015
    Messages:
    3,504
    Resources:
    20
    Models:
    2
    Icons:
    10
    Spells:
    7
    Tutorials:
    1
    Resources:
    20
    And for God's sake please do not use Hive's leak tester and manually check your own leaks. Please.
     
  7. blancfaye7

    blancfaye7

    Joined:
    May 21, 2014
    Messages:
    560
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Regarding these, it feels like this is something I need to watch out for myself IMHO.
     
  8. StoPCampinGn00b

    StoPCampinGn00b

    Community Manager

    Joined:
    Apr 2, 2013
    Messages:
    2,459
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Pretend the use of "I" or "me" in my post is myself as a new modder.
    This doesn't tell my what a memory leak is in relation to modding WC3 / SC2. It gives the base technical coding details of what it does in general, but not what's actually important to know from my perspective. It means very little to anyone who has no background in modding, which is why it was probably skimmed over by anyone reading this.

    What's important to know for your readers is more valuable than having a spiffy English class definition.

    There should be more emphasis on leaks causing maps to have bugs, crashes, and lag. It states so, but in more vague and general ways without mentioning maps.

    So yeah, those are my suggestions :). This came to my mind because I'm suggesting to link this in our JASS / Leak Checker feature up top.
     
    Last edited: Sep 17, 2016
  9. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,272
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    At first I want to introduce the reader of what a memory leak actually is, in general. I think it's fine.
    Though I agree I should add something to relate also to warcraft specificaly in the end of the introduction. I will add a little paragraph for it, thanks. :)
     
  10. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,272
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Added a topic about data types. If I wrote wrong information or missed something, please give your input.
     
    Last edited: Oct 29, 2016
  11. Aniki

    Aniki

    Joined:
    Nov 7, 2014
    Messages:
    524
    Resources:
    4
    Spells:
    1
    JASS:
    3
    Resources:
    4
    It seems that structs/objects that bundle up primitive/other structs/objects types are referred to as "composite/aggregate" types and not "complex" (oh I guess it's a synonym).

    Anyway... I have this list of lists that tries to "classify" Jass's types (it's fairly biased):

    Code (vJASS):

    primitive: [
        integer,
        real,
        boolean,
        string,
        code,
        handle,
    ],

    intresting: [
        string, // any string when displayed can be colored using a code: |cffFF0000<this-text-will-be-displayed-in-red>|r
        unit, item, ability, buff,
        destructable,
        trigger, event,
        timer, timerdialog,
        rect,
        sound,
        camerasetup,
        effect,
        weathereffect,
        terraindeformation,
        fogmodifier,
        dialog, button,
        multiboard, multiboarditem, leaderboard,
        trackable,
        gamecache,
        texttag,
        lightning,
        image,
        <text-to-player>, // DisplayTimedTextToPlayer
        <cine-filter>, <cinematic-cine>,
    ],

    unintresting: [
        player, // glorified integer
        agent,
        widget,
        force,
        group,
        triggercondition, triggeraction,
        quest, questitem, defeatcondition,
        location,
        region,
        boolexpr, conditionfunc, filterfunc,
        unitpool, itempool,
        ubersplat,
        hashtable,
    ],

    not-savable-in-hashtable: [
        // code, // can't have code arrays (modulo bug) either so...
        camerasetup,
        weathereffect,
        terraindeformation,
        gamecache,
    ],

    enums: [
        race,
        alliancetype,
        racepreference,
        gamestate, igamestate, fgamestate,
        playerstate,
        playerscore,
        playergameresult,
        unitstate,
        aidifficulty,
        eventid,
        gameevent,
        playerevent,
        playerunitevent,
        unitevent,
        limitop,
        widgetevent,
        dialogevent,
        unittype,
        gamespeed,
        gamedifficulty,
        gametype,
        mapflag,
        mapvisibility,
        mapsetting,
        mapdensity,
        mapcontrol,
        fogstate,
        playerslotstate,
        volumegroup,
        camerafield,
        playercolor,
        placement,
        startlocprio,
        raritycontrol,
        blendmode,
        texmapflags,
        effecttype,
        version,
        itemtype,
        attacktype,
        damagetype,
        weapontype,
        soundtype,
        pathingtype,
    ],

    @TODO: which of the handle extending types (non-enum) use handle-ids >= 0x00_10_00_00 and which use their own specific handle-id pool (e.g: texttag(s))

     


    The reason I am pasting it is because of that TODO at the end which is related to handle-id leaks. So maybe we (by we I mean you ;P) can make two list of handles, the ones that have an id (GetHandleId) >= 0x00_10_00_00 and the ones that have ids starting from 1 I guess?

    PS: I think its worth noting that every type can be convert and/or casted to/from an integer, some are just a bit harder than others. [1]
     
    Last edited: Oct 29, 2016
  12. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,272
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Thanks for the list. I'm not very sure we accuratly need to distinguish all these categorizations in "Memory Leaks", but maybe it's also a nice info.
    Hm.. maybe it's even worth to create a seperate tutorial about data types. Because enums are, yeah, are to treat differently than agents for example.

    Will also think some more about it. ^^
     
  13. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,846
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    Every agent uses handle id of 0x100000 and any nonagent handle uses its own afaik. They dont start from 1 either, texttag for instance starts at 100 and goes down to 0.
     
  14. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,272
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    @Aniki how you exactly detinguish between intresting and unintresting? I'm not sure I can follow all elements.
    Those enums are some sort of integer wrappers, but no real objects, so yeah we could actually seperate them clearly from other ones.
     
  15. Aniki

    Aniki

    Joined:
    Nov 7, 2014
    Messages:
    524
    Resources:
    4
    Spells:
    1
    JASS:
    3
    Resources:
    4
    Like I said, the list is biased, but lets see:
    Code (vJASS):


    uninteresting: [
        // I don't see the point of this type not being an integer or implicitly convertable to one.
        // Its just annothing having to call GetPlayerId (player -> integer) and Player (integer -> player)
        // manually all the time. I think in SC2 this type is indeed an integer.
        player,

        // I don't know why this type was introduced when Blizzard made the hashtable natives.
        // It seems pretty pointless.
        agent,

        // Units, items and destructables are widgets... so we have inheritance there... I just don't like
        // inheritance (I do like tagged/discriminated unions =), instead), but at least its only 1 level
        // of inheritance (I guess Blizzard learned their lesson from SC1 :P).
        // So okay, maybe not that uninteresting.
        widget,

        // A non-random-access collection of player(s) with callback iteration...
        force,

        // A non-random-access collection of unit(s) with optional callback iteration,
        // slightly better than force, thanks to FirstOfGroup, but FirstOfGroup has
        // issues of its own (GroupRefresh), so yeah... not really interesting.
        group,

        // Removing an event listener (trigger)'s handler functions...
        triggercondition, triggeraction,

        // These are here because they are cumbersome to read when one wants to put
        // a lot of text in the quests menu.
        quest, questitem, defeatcondition,

        // I wish location was a primitive type (like integer/real), i.e not having to bother
        // calling RemoveLocation and nulling them, but they are not, which makes them annoying to use,
        // unfortunately.
        location,

        // Just because of the confusion it creates with using the event "unit enters rect".
        region,

        // Code pointing to a function with a boolean return value?
        boolexpr, conditionfunc, filterfunc,

        // I don't think Blizzard used these in WE's jass generation, I guess they are kind of
        // intersting from algorithmic point of view.
        unitpool, itempool,

        // Image, ubersplat, what's the difference?
        ubersplat,

        // I think we have to thank dota's ubiquitous use of gamecache (and not structs, I don't think "dota knows" what a struct is)
        // and the return bug for this overused type. It's occasionally useful, but not as interesting as gamecahe.
        hashtable,
    ],
     
     
  16. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,272
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Thanks for your thoughts. Hm.. about the list of important obejcts, that have to be actually cared about (destroyed), without all the integer wrappers enums... I think that this might be a paragraph in "Data Types" topic.
    But I also don't wanna bloat the tutorial, I try to find something short next days to mention it. (and just add a [HlDDEN] list or so)

    The other seperation, might be interesting, too, but maybe it's not worth to note it directly in this tutorial. They require only to know what they need to destroy & what to "null" here.
    But maybe there really can be a full tutorial all about different types, explainations and thoughts about them.
     
  17. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    400
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    Hmm, setting bj_wantDestroyGroup to true does not automatically destroy groups in any case when using GUI <UnitGroup - Pick units in UnitGroup> actions. It always return a group. You can verify this by looking at the function in jass.

    EDIT:
    bj_wantDestroyGroup are only used if you want to automatically destroy a group in functions that take a group and returns another group, but it will only destroy the group passed as an argument and the function still returns a new group. Example of these functions are CountUnitsInGroup(), GroupAddGroup(), GroupRemoveGroup(), etc...

    I see this being done widely for a long time now by GUIers, and it's only now that I actually checked it and realized this isn't the case.

    :oops:
     
    Last edited: Nov 27, 2016
  18. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,272
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Can check converted GUI tomorrow when I'm at home, but from Blizzard.j - WarCraft3 :

    Isnt this the GUI ForGroup:
    Code (vJASS):

    function [URL='http://wiki.thehelper.net/wc3/jass/Blizzard.j/ForGroupBJ']ForGroupBJ[/URL] takes [URL='http://wiki.thehelper.net/wc3/jass/common.j/group']group[/URL] whichGroup, [URL='http://wiki.thehelper.net/wc3/jass/common.j/code']code[/URL] callback returns [URL='http://wiki.thehelper.net/wc3/jass/common.j/nothing']nothing[/URL]
       // If the user wants the group destroyed, remember that fact and clear
        // the flag, in case it is used again in the callback.
        local [URL='http://wiki.thehelper.net/wc3/jass/common.j/boolean']boolean[/URL] wantDestroy = [URL='http://wiki.thehelper.net/wc3/bj_wantDestroyGroup']bj_wantDestroyGroup[/URL]
        set [URL='http://wiki.thehelper.net/wc3/bj_wantDestroyGroup']bj_wantDestroyGroup[/URL] = false

        call [URL='http://wiki.thehelper.net/wc3/jass/common.j/ForGroup']ForGroup[/URL](whichGroup, callback)

        // If the user wants the group destroyed, do so now.
        if (wantDestroy) then
            call [URL='http://wiki.thehelper.net/wc3/jass/common.j/DestroyGroup']DestroyGroup[/URL](whichGroup)
        endif
    endfunction


    And internaly something like this is passed as argument:
    Code (vJASS):

    function [URL='http://wiki.thehelper.net/wc3/jass/Blizzard.j/GetUnitsInRangeOfLocMatching']GetUnitsInRangeOfLocMatching[/URL] takes [URL='http://wiki.thehelper.net/wc3/jass/common.j/real']real[/URL] radius, [URL='http://wiki.thehelper.net/wc3/jass/common.j/location']location[/URL] whichLocation, [URL='http://wiki.thehelper.net/wc3/jass/common.j/boolexpr']boolexpr[/URL] filter returns [URL='http://wiki.thehelper.net/wc3/jass/common.j/group']group[/URL]
       local [URL='http://wiki.thehelper.net/wc3/jass/common.j/group']group[/URL] g = [URL='http://wiki.thehelper.net/wc3/jass/common.j/CreateGroup']CreateGroup[/URL]()
        call [URL='http://wiki.thehelper.net/wc3/jass/common.j/GroupEnumUnitsInRangeOfLoc']GroupEnumUnitsInRangeOfLoc[/URL](g, whichLocation, radius, filter)
        call [URL='http://wiki.thehelper.net/wc3/jass/common.j/DestroyBoolExpr']DestroyBoolExpr[/URL](filter)
        return g
    endfunction

    ^which does normaly return a group, but that will be destroyed later by the ForGroupBJ.

    edit: Argh sorry for the broken code. But first one is ForGroupBJ and second one GetUnitsInRangeOfLocMatching.
     
  19. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    400
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    Ah yes XD My bad
    I though it is just a wrapper a single function ForGroup().:D