• 🏆 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!

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.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
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