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 Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    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.

[JASS] [Jass] Trying to find memory leaks

Discussion in 'Triggers & Scripts' started by Kamulec, May 19, 2014.

  1. Kamulec

    Kamulec

    Joined:
    May 15, 2008
    Messages:
    104
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Hi guys.

    I am not sure if there are any memory leaks in my map but I would like to find out. I don't see them and that's why I ask you for help. Please check my code and tell me if you see (or not) any memory leaks in it (I don't care about any other measures). I would strongly appreciate your help.


    Code (vJASS):
    function Trig_LeavingArea_Func107 takes integer int returns boolean
        return ( int <= 107 )
    endfunction

    function Trig_LeavingArea_Func106 takes integer int returns boolean
        return ( int >= 106 )
    endfunction

    function Trig_LeavingArea_FuncShipyard takes integer int returns boolean
        return GetBooleanAnd( Trig_LeavingArea_Func106(int), Trig_LeavingArea_Func107(int) )
    endfunction

    function Trig_LeavingArea_FuncControl takes integer int returns nothing
        local player playerL = GetOwningPlayer(GetTriggerUnit())
        if ( Trig_LeavingArea_FuncShipyard(int) ) then
            call SetUnitOwner( udg_Area_Shipyards[int], playerL, true )
        endif
        call SetUnitOwner( udg_Area_Towns[int], playerL, true )
        call SetUnitOwner( udg_Area_Towers[int], playerL, true )
    endfunction

    //===========================================================================

    function Trig_LeavingArea_FuncIfNotStructure takes unit u returns boolean
        return ( IsUnitType(u, UNIT_TYPE_STRUCTURE) == false )
    endfunction

    function Trig_LeavingArea_FuncIfNotFlying takes unit u returns boolean
        return ( IsUnitType(u, UNIT_TYPE_FLYING) == false )
    endfunction

    function Trig_LeavingArea_FuncIfNotDead takes unit u returns boolean
        return ( IsUnitAliveBJ(u) == true )
    endfunction

    function Trig_LeavingArea_FuncIfNotFlyingDeadStructure takes unit u returns boolean
        return GetBooleanAnd( Trig_LeavingArea_FuncIfNotDead(u), GetBooleanAnd( Trig_LeavingArea_FuncIfNotStructure(u), Trig_LeavingArea_FuncIfNotFlying(u) ) )
    endfunction

    function Trig_LeavingArea_FuncIfNotFlyingDeadStructureFilter takes nothing returns boolean
        return Trig_LeavingArea_FuncIfNotFlyingDeadStructure( GetFilterUnit() )
    endfunction

    function Trig_LeavingArea_FuncIfNumberOfUnitsInGroup takes integer int returns boolean
        local integer number = 0
        local group gArea = CreateGroup()
        set gArea = GetUnitsInRectMatching(udg_Area_Region[int], Condition(function Trig_LeavingArea_FuncIfNotFlyingDeadStructureFilter))
        set number = CountUnitsInGroup(gArea)
        call DestroyGroup(gArea)
        return ( number == 0 )
    endfunction


    function Trig_LeavingArea_FuncIfAreaContainsTriggeringUnit takes integer number returns boolean
        if ( not ( RectContainsUnit(udg_Area_RegionPlus[number], GetTriggerUnit()) == true ) ) then
            return false
        endif
        return true
    endfunction

    function Trig_LeavingArea_Actions takes nothing returns nothing
        local integer j = 1
        if ( Trig_LeavingArea_FuncIfNotFlyingDeadStructure(GetTriggerUnit()) ) then
            loop
                exitwhen j > udg_NumberOfTowns
                if ( Trig_LeavingArea_FuncIfAreaContainsTriggeringUnit(j) ) then
                    if ( Trig_LeavingArea_FuncIfNumberOfUnitsInGroup( j ) ) then
                        call SetUnitPositionLoc( GetTriggerUnit(), udg_Area_Center[j] )
                        call IssueImmediateOrderBJ( GetTriggerUnit(), "holdposition" )
                        call Trig_LeavingArea_FuncControl(j)
                    else
                    endif
                    return
                else
                endif
                set j = j + 1
            endloop
        else
        endif
    endfunction


    //===========================================================================


    function LeavingArea_onStart takes nothing returns nothing
         local integer i = 1
         call DestroyTimer(GetExpiredTimer())
         set gg_trg_LeavingArea = CreateTrigger(  )
         loop
             exitwhen i > udg_NumberOfTowns
             call TriggerRegisterLeaveRectSimple( gg_trg_LeavingArea, udg_Area_Region[i])
             set i = i + 1
         endloop
         call TriggerAddAction( gg_trg_LeavingArea, function Trig_LeavingArea_Actions )
    endfunction

    function InitTrig_LeavingArea takes nothing returns nothing
         call TimerStart(CreateTimer(), 0, false, function LeavingArea_onStart)
    endfunction


    ©Kamulec 2008-2014
     
    Last edited: May 23, 2014
  2. Geshishouhu

    Geshishouhu

    Joined:
    Oct 11, 2012
    Messages:
    710
    Resources:
    1
    Spells:
    1
    Resources:
    1
    If your only concern is memory leak, then I don't see any leak in your code (assuming the global rects and "udg_Area_Center[j]" need to be reused). But I have to say you need to optimize your code. LOL
     
  3. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,181
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    local group gArea = CreateGroup()

    null this in end of your function. Else no leak, but not good coding. (also mixing with gui)
     
  4. Geshishouhu

    Geshishouhu

    Joined:
    Oct 11, 2012
    Messages:
    710
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Oops, how did I miss that... I'm sorry.
    Yea, u need to null that local group variable.