• 🏆 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!

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