HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

What The Heck?

03-07-2010, 12:16 PM#1
TheKid
Collapse 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

This is a function included in Blizzard's API; there are a few things rather strange about it. First of all, filterGetUnitsOfTypeIdAll is shown as a constant (and highlighted in my JNGP) but I can't seem to find it anywhere.

Also, I was very curious about this; notice how it returns result at the end of the function? Would that cause a leak in memory when the reference "result" becomes un-used?
03-07-2010, 04:13 PM#2
Earth-Fury
The global is in blizzard.j:
Collapse JASS:
    set filterGetUnitsOfTypeIdAll = Filter(function GetUnitsOfTypeIdAllFilter)

And blizzard has lots of leaky functions.

Edited because: I copied the wrong line. Whoops..

Collapse JASS:
    boolexpr           filterGetUnitsOfTypeIdAll         = null
03-07-2010, 08:04 PM#3
Fledermaus
result is obviously a global so it shouldn't leak.
03-07-2010, 08:09 PM#4
Earth-Fury
Quote:
Originally Posted by Fledermaus
result is obviously a global so it shouldn't leak.

Quote:
Originally Posted by TheKid
Collapse 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

Quote:
Originally Posted by TheKid
Collapse JASS:
function GetUnitsOfTypeIdAll takes integer unitid returns group
    local group   result = CreateGroup()
    local group   g      = CreateGroup()
    local integer index
    // ...
    return result
endfunction

Quote:
Originally Posted by TheKid
Collapse JASS:
function GetUnitsOfTypeIdAll takes integer unitid returns group
    local group   result = CreateGroup()
    // ...
    return result
endfunction

Quote:
Originally Posted by TheKid
Collapse JASS:
    local group   result = CreateGroup()

Quote:
Originally Posted by TheKid
Collapse JASS:
    local group   result = CreateGroup()
03-07-2010, 08:11 PM#5
TheKid
I felt like I was being zoomed in.

Quote:
Originally Posted by Fledermaus
result is obviously a global

Obviously.
03-08-2010, 12:53 AM#6
Fledermaus
Fleder is obviously blind *blush*

Anyway, since it returns a created group, it will leak unless you destroy it when you are done with it.
03-08-2010, 02:07 AM#7
TheKid
Collapse JASS:
local group g1 = CreateGroup()
local group g2 = CopyGroup(g1)

They both act the same way, and both need to be destroyed the same way.