• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Does this leak? Yes? No?

Status
Not open for further replies.
Level 7
Joined
Jul 19, 2008
Messages
58
just wondering...didn't see it on forums
vvv

JASS:
function Test takes nothing returns nothing
   local location l
   local location l2
endfunction

does it produce a handle? would I have to make it...

JASS:
function Test takes nothing returns nothing
   local location l
   local location l2
   set l=null
   set l2=null
endfunction
????
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
lol wow two different responses, but i believe purge more :)
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
Like this.
No locations, no handle leaks.
 
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.

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. =)
 
Status
Not open for further replies.
Top