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

[JASS] do GetOwningPlayer() and other Get functions leak?

Status
Not open for further replies.
Level 2
Joined
Apr 25, 2008
Messages
17
Is this (GetOwningPlayer()) a leak? .. actually do all the get functions leaks such as GetEnumUnit()? Im trying to minimise the number of leaks in my AI but i have many triggering events such as
GetPlayerId(GetOwningPlayer(GetEnteringUnit()))

is this a leak because im thinking of creating locals for GetOwningPlayer() and GetEnteringUnit() then destroying them but then having a local created and destroyed everytime a unit enters <-- isnt this more processing?

Also the GetEnumUnit(), does this leak because i have this running for all units in the entire map and all units in each player's base.
 
Level 2
Joined
Apr 25, 2008
Messages
17
maybe i wasnt too clear with what i was saying for example this function

JASS:
    local integer i = GetPlayerId(GetOwningPlayer(GetEnteringUnit())) 
    local location l    
    if (i<5) then
        set l = GetRandomLocInRect(gg_rct_Red_Army_1b) )  
    else
        set l = GetRandomLocInRect(gg_rct_Blue_Army_1b) )   
    endif   
    call IssuePointOrderLoc( udg_CPU[i], "attack", l)   
    set udg_targetPoint[i] = l    
    call floatText ("Going to zone 1b", i)
    call RemoveLocation(l)
    set l = null

and this code local integer i = GetPlayerId(GetOwningPlayer(GetEnteringUnit()))

would it be better if i made it
local unit u = GetEnteringUnit()
local player p = GetOwningPlayer(u)

call DestroyUnit(u)
call DestroyPlayer(p)
set u = null
set p = null
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
your code is not fine
because you remove targetPoint's too
RemoveLocation(udg_targetPoint) later in code instead of removing l
OR
make it set udg_targetPoint = Location(GetLocationX(l),GetLocationY(l))

locations are like units

think there are 2 location variables
local location a = Location(1,1)
local location b = a
if you remove a you remove b too
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Functions don't leak, variables do.
A leak is when you have a variable pointing to a value (and thus its called a Pointer) even though the value was destroyed / is unnecessary.

Now since you get players, and players are constants (player 1 will always be player 1 for example), there is no reason it would leak.

As to the functions you presented, both of them are exactly the same
JASS:
local integer i = GetPlayerId(GetOwningPlayer(GetEnteringUnit())) 
Action that uses i.

// this is exactly like this

local unit u = GetEnteringUnit()
local player p = GetOwningPlayer(u)
Action that uses p
 
Status
Not open for further replies.
Top