• 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.

GroupClear

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
Would a unit group leak if only used GroupClear? Because for me, DestroyGroup either a.) makes the next ForGroup only pick one unit, b.) does not pick at all, or c.) messes with add/remove unit.
Well if you try and use something that has been destroyed what do you expect? I mean you would hardly go back to living in a building after it has been demolished would you? Once a group has been destroyed all variables pointing at it will have a destroyed handle and so any operations that use such variables will not work. You will need to set the variable to a new, freshly created group for them to work again.
 
Well if you try and use something that has been destroyed what do you expect? I mean you would hardly go back to living in a building after it has been demolished would you? Once a group has been destroyed all variables pointing at it will have a destroyed handle and so any operations that use such variables will not work. You will need to set the variable to a new, freshly created group for them to work again.
The variables are set. So why do those even happen?
 
You don't use this bj_destroy with combination of a varibale or?
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in UnitgroupVariable and do Actions:
After this you would be not able to use it anymore.

Actually that would not do anything since it does not call the function that creates a unit group. So yes you would be able to use it again.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
Groups are cleared upon enumeration if I remember correctly.
Yes if you are using the natives directly. GUI's BJs create a new group...

JASS:
function GetUnitsInRangeOfLocMatching takes real radius,location whichLocation,boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(g, whichLocation, radius, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

function GetUnitsInRectMatching takes rect r,boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, r, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

function GetUnitsInRectOfPlayer takes rect r,player whichPlayer returns group
    local group g = CreateGroup()
    set bj_groupEnumOwningPlayer = whichPlayer
    call GroupEnumUnitsInRect(g, r, filterGetUnitsInRectOfPlayer)
    return g
endfunction

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

function GetUnitsOfPlayerMatching takes player whichPlayer,boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

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

function GetUnitsSelectedAll takes player whichPlayer returns group
    local group g = CreateGroup()
    call SyncSelections()
    call GroupEnumUnitsSelected(g, whichPlayer, null)
    return g
endfunction

Yeh so in JASS it is no problem to recycle groups, but GUI does not really support it.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
Meanwhile, can you please clarify if creating locals at either of these will take much memory:
Why would you be concerned about the memory use? I mean JASS variables are only a couple dozen bytes and all locals are removed when the thread dies anyway. Locals do not and cannot leak in WC3 (as far as I know).

What does leak with locals are handle indexes. When a function returns it does not decrement the reference counter of local handles resulting in a reference leak so the index can never be recycled. Logically only applies to types which can be recycled such as units, locations, groups etc. This does not apply to local handles declared as function arguments since they operate correctly and do decrement reference counters on function return.
 
Status
Not open for further replies.
Top