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!
Even worse, it leaks a location handle and a local variable!
JASS:
function Test takes nothing returns nothing
local location l
local location l2
call RemoveLocation(l)
call RemoveLocation(l2)
set l=null
set l2=null
endfunction
are you going to be setting the variable to anything? if you are, you'll need to do what i said
if you don't just leave it, you don't even need to null it if you're not setting it to anything, but if you are i'd just use "null" instead of "insert variable name here"
The replies are the same.
Purge just understood something differently, that's all.
If you use local location L, it will not give a handle leak. However: if you then use set L = Location or simply do local location L = Location, it will leak.
It's highly unlikely that you will just do this:
JASS:
function loc takes nothing returns nothing
local location l
set l = null
endfunction
This is what Purge said: since the location isn't used, it doesn't create a handle leak and you don't need to remove anything.
The function above is leakless (no RemoveLocation required).
what ikillforyou said is basically this:
JASS:
function loc takes nothing returns nothing
local location l = Location
call RemoveLocation(l)
set l = null
endfunction
It's very obvious: you're creating a local variable, so you're probably going to set it to a location as well.
Therefore, it will leak, because it accesses a handle (a location in this case).
If you're going to create a local wihout actually setting it to something (like in the first function), don't create it, it's as simple as that.
Therefore I think Purge is wrong (he said it doesn't leak, which is correct, but why nullify it then? Just removing the entire variable would be the best option in that case).
On the other hand: don't use locations either.
Use coördinates (reals): they don't give handle leaks and you wouldn't have this problem in the first place.
JASS:
function loc takes nothing returns nothing
local real X = GetUnitX(unit)
local real Y = GetUnitY(unit)
endfunction
Yeah, the best option would be to remove a useless variable. But sometimes, you might come into something like this:
JASS:
function Whee takes nothing returns nothing
local location L
if GetSpellAbilityId()=='A034' then
set L = Location(0,0)
call DestroyEffect(AddSpecialEffectLoc("string.mdl",L))
call RemoveLocation(L)
set L = null
endif
endfunction
It might make people wonder whether they need to move the two outside the if-block as well. So it is situational. =)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.