• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Does last created unit group leaks

Status
Not open for further replies.
Level 28
Joined
Jan 26, 2007
Messages
4,789
For unit groups, you don't need a variable.

Before using the unit group, you can add the line
  • Custom script: set bj_wantDestroyGroup = true
Then do the unit group actions.

Units don't leak, locations (points) do though.


Further reading.
(The rest of the thread can also be useful if you'd like to know more about leaks :D).

Edit: the JASS lines you see there can easily be used in GUI with the "Custom script"-action.
 
Level 9
Joined
Jul 10, 2011
Messages
562
i could be wrong but i remeber that i read that the GUI 'last created unit' creates a group in background so that would leak.

could be wrong but i think i read it. maybe a jasser could say whether im right^^
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
So this script does not leak eh apo ?
  • Actions
    • Set TempLoc = (Position of (Triggering unit))
    • Unit - Create 10 Footman for Player 1 (Red) at TempLoc facing Default building facing degrees
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Last created unit group) and do (Actions)
      • Loop - Actions
        • Unit - Kill (Picked unit)
    • Custom script: call RemoveLocation(udg_TempLoc)
Let's focus on the "Pick every unit..." action.
Just by adding set bj_wantDestroyGroup = true destroys the leak ?
 
@defskull: Yes. "Pick every unit..." translates to ForGroupBJ(). ForGroupBJ() checks if bj_wantDestroyGroup after it calls the ForGroup() function and will destroy the group if you want it to.
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 28
Joined
Jan 26, 2007
Messages
4,789
Since we're related to the topic, might as well ask a question;
Does this leak ?
  • Unit - Kill (Random unit from (Random 1 units from TempGroup))
Don't focus on the TempGroup, just focus on the function Random unit from...
Yes, this leaks.
You're actually using 2 unit groups: Random units from (group) and (group) itself.
Even though you're only picking 1 unit, Warcraft will always put it in a newly created unit group.

You should destroy both groups (this also means that "set bj_wantDestroyGroup" doesn't work for both of them: you should store at least 1 group in a variable, like you did).
 
Status
Not open for further replies.
Top