• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Does this creates a leak?

Status
Not open for further replies.
Level 3
Joined
May 7, 2016
Messages
38
I am basically asking if it leeks if i never destroy the group and just use "add unit" and "remove unit"
  • For each (Integer A) from 1 to 4, do (Actions)
    • Loop - Actions
      • Unit Group - Pick every unit in T_US_TR_Selected[(Integer A)] and do (Actions)
        • Loop - Actions
          • Unit Group - Remove (Picked unit) from T_US_TR_Selected[(Integer A)]
  • Unit Group - Pick every unit in T_US_TR_Towers and do (Actions)
    • Loop - Actions
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is selected by (Player((Integer A)))) Equal to True
            • Then - Actions
              • Unit Group - Add (Picked unit) to T_US_TR_Selected[(Integer A)]
            • Else - Actions
 
Level 6
Joined
Feb 5, 2012
Messages
1,685
Yes it leak as far as I know.


Don't worry it will not do so much since your just creating a group once then recylce it.

Even creating a unit leaks. But as long as you have only small amount of that, thats ok.

Also you can't destroy it since it will mess up your triggers so just remove that things that leaks A LOT.
 

EdgeOfChaos

E

EdgeOfChaos

No. Adding/removing never causes a leak. When you use GUI, only things like "Pick every unit in __" leaks.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
I thought if you started using unit groups they add memory.
It does add to memory, but that is not what it leak is. A leak is when you lose reference to that space in memory, meaning that it is senselessly taking up space.

When you use GUI, only things like "Pick every unit in __" leaks.
The function itself doesn't leak. It only leaks if you let it create a unit group for you without setting the bj_wantDestroyGroup boolean to true.
 
Level 3
Joined
May 7, 2016
Messages
38
Soo currently i am using that group to see if the number of units selected by player is = 1
  • For each (Integer A) from 1 to 4, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in T_US_TR_Selected[(Integer A)]) Equal to 1
        • Then - Actions
          • Set T_US_TR_OneSelect[(Integer A)] = True
        • Else - Actions
          • Set T_US_TR_OneSelect[(Integer A)] = False
and than use command
  • Set T_US_TR_UnitSelected = (Random unit from T_US_TR_Selected[(Integer A)])
to get that "one" unit.
soo does that leak?
And btw
  • bj_wantDestroyGroup
only destroys the next or must i set it to false next command?
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Yes it will leak.

And btw
  • Custom script: bj_wantDestroyGroup
only destroys the next or must i set it to false next command?

The function will set it to false for you. You only need to set it to true before you create the unit group if you want to destroy the it after the loop is done.
JASS:
function ForGroupBJ takes group whichGroup, code callback returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    call ForGroup(whichGroup, callback)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
endfunction
 
Level 3
Joined
May 7, 2016
Messages
38
Hmm that is nice and all but the problem is the 1st variable(T_US_TR_Towers) i keep as a constant and i don't want it deleted, the 2nd array variable(T_US_TR_Selected[]) is to make 4 unit groups for 4 players that consists of units they did select(the changing one) and (this) trigger fires only when "player selects a unit" and there is a 2nd trigger(Time - Every 0.01 seconds of game time
) that is playing with that (selected) unit.
Soo i don't want the group deleted becose the trigger 2 i using it 100 times a second
 
Status
Not open for further replies.
Top