• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Simple "yes or no" question about leaks

Status
Not open for further replies.
Level 4
Joined
Feb 28, 2014
Messages
70
  • Unit Group - Pick every unit in (Units owned by Player 7 (Green) of type Boulder) and do (Actions)
    • Loop - Actions
Does this action leak a unit group?

  • Unit Group - Pick every unit in (Units owned by Player 7 (Green) of type Boulder) and do (Actions)
    • Loop - Actions
Yes

  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units owned by Player 7 (Green) of type Boulder) and do (Actions)
    • Loop - Actions
No
 
Level 14
Joined
Aug 30, 2004
Messages
909
Thanks for the help everyone, +rep all around.

I thought there was some exception to the unit group leak if you picked all units of a particular type... I don't know where I got that from, but it's a simple fix.

Thanks again!
 
PickEveryUnitByPlayerOfType:
JASS:
function GetUnitsOfPlayerAndTypeId takes player whichPlayer, integer unitid returns group
    local group g = CreateGroup()
    set bj_groupEnumTypeId = unitid
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterGetUnitsOfPlayerAndTypeId)
    return g
endfunction
^Does not recycle the HandleId of "g".

PickEveryUnitOfType:
JASS:
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
^Does not recycle the HandleId of "g" and "result". -> leaks 2 references -> worse.

You probably have seen one of Maker's posts, iirc he was one guy who recommended not to use it. :csmile:
 
Status
Not open for further replies.
Top