• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

How bad are leaks??

Status
Not open for further replies.
Level 6
Joined
Jan 4, 2014
Messages
227
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
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
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
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).
 
Level 6
Joined
Jan 4, 2014
Messages
227
JASS:
function MyFun takes unit u returns nothing
    local localtion 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.

Only if you don't use the "set" keyword on them within that function. It's the "set" ketword that adds an extra reference that needs to be nulled. Otherwise, yes.
 
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:

JASS:
function foo takes nothing returns unit
    local unit u = CreateUnit('hfoo', Player(0), 0, 0, 0)
    return u
endfunction

Hence why some (few) people suggest to do something like this:

JASS:
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

The question is: is this still valid or was this fixed by Blizzard? Because I have never done that and never experienced any performance issues ever, even after multi-hour sessions.
 
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)
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 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.
This is bad.
How is this not public knowledge then? This means that any periodic function that returns a handle should actually return a global then.
 
Status
Not open for further replies.
Top