• 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.

does this leak?

Status
Not open for further replies.
Level 23
Joined
Apr 16, 2012
Messages
4,041
I ever did it this way but calling set u = null for every unit in group can slow things down and even Nestharus didnt do that in his vJass tut. video so my question is:
JASS:
    local group g = CreateGroup()
    local unit u
    call GroupEnumUnitsInRange(g, blabla whatever) // this is not important
    loop
        set u = FirstOfGroup()
        exitwhen u == null
        call GroupRemoveUnit()
        //some actions
    endloop
    set u = null
There is no set u = null in the loop so I wonder if this leak because it was said that everytime you give some handle pointer a value(set u = FirstOfGroup() for instance) it must be nulled to make the pointer free(number of sets and number of nulls must be equal)
 
Well, you do not have to set u = null all the time, only on the end of the function. Local variables must be nulled if they are handles, because if they do not get recycled (nulled) they still point to something, which means that handle id can't get recycled. This means that the handle stack goes up, and there is a set number of handles a map can have.

Basically, that doesn't leak because you only have to null locals on the end of the function (which is what you are currently doing).
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
well, i mean
JASS:
local group g = CreateGroup()
local unit u
call GroupEnumUnitsInRange(g, blabla whatever) // this is not important
loop
    set u = FirstOfGroup()
    exitwhen u == null
    call GroupRemoveUnit()
    //some actions
    set u = null
endloop
thats how i used to do it :D(and I still do for now)
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
What McKill means is: You do not need to do set u = null inside the loop, as you immediately use the unit again, and furthermore, since you put exitwhen u == null, you also do not have to null it after the loop, since u is already null.
 
what is difference between local group and the global one other then 3 less calls
why create a local group for enumerating when it's already there via bj_lastCreatedGroup, besides you should destoy your local group which means it's 50% slower than the method I showed you...but ofc nothing wrong with what you did...
 
Status
Not open for further replies.
Top