• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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