That's because the "Units In Range"-function is flawed/Blizzard screwed up local agent variables. It looks like this:
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 GetUnitsInRangeOfLocAll takes real radius, location whichLocation returns group
return GetUnitsInRangeOfLocMatching(radius, whichLocation, null)
endfunction
In the upper function, a local variable g is pointed to the group object but never nullified. An object cannot free its id before all variables/references are gone from it but local variables are not auto-deleted when the function call terminates, therefore in the example above, the object always ends up with one remaining reference. Avoid the function/write an alternative, e.g.:
function GetUnitsInRangeOfLocMatchingFixed takes real radius, location whichLocation, boolexpr filter returns group
local group g = CreateGroup()
call GroupEnumUnitsInRangeOfLoc(g, whichLocation, radius, filter)
call DestroyBoolExpr(filter)
set udg_unusedGroupVariable = g
set g = null
return udg_unusedGroupVariable
endfunction
function GetUnitsInRangeOfLocAllFixed takes real radius, location whichLocation returns group
return GetUnitsInRangeOfLocMatchingFixed(radius, whichLocation, null)
endfunction
where udg_unusedGroupVariable is some elsewhere unused global group variable.