You need to RemoveLocation of course. Then null the variable. But in JASS, locations are rarely used since it can be represented by real variables x and y. Instead of GetUnitLoc(u), we used GetUnitX(u) and GetUnitY(u).Exemple :
JASS:function MyFun takes unit u returns nothing local localtion l = GetUnitLoc(u) //Do some stuff with the location l = null //Does this cleares the handle ? endfunction
JASS:function MyFun takes unit u returns nothing local location l = GetUnitLoc(u) //Do some stuff with the location call RemoveLocation(l) set l = null endfunction
so in case where i use a location this how i clear it correctly ??
It is important to note that only local declared local handle variables leak a handle reference count on function return. Parameter declared local handle variables do correctly manage the handle reference counter on function return.
Interestingly enough, I've seen people that say that this actually does leak a reference:It is important to note that only local declared local handle variables leak a handle reference count on function return. Parameter declared local handle variables do correctly manage the handle reference counter on function return.
function foo takes nothing returns unit
local unit u = CreateUnit('hfoo', Player(0), 0, 0, 0)
return u
endfunction
globals
unit tempunit
endglobals
function bar takes nothing returns unit
local unit u = CreateUnit('hfoo', Player(0), 0, 0, 0)
set tempunit = u
set u = null
return tempunit
endfunction
Depends. It's more or less the same problem as with parameter-declared variables (which, mind you, don't leak)... it depends on the internal implementation of Jass. You can't say for sure that it leaks just because the variable is not nulled properly. Jass might be implemented in a way that always nulls a local variable on return.it should by the logic leak, because the local variable u is never nulled, so for the game the newly created unit will always have at least 1 reference to it(ref count will be 1)
This is bad.It doesn't. I have checked the handle reference stack for recycled indices and it does not recycle local handles which weren't nulled, even if that same handle was returned.