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

[JASS] Nullify question

Status
Not open for further replies.
Level 23
Joined
Nov 29, 2006
Messages
2,482
Hm well im going to make an example, and then pose the question

JASS:
globals
multiboard udg = CreateMultiboard()
endglobals

function example takes nothing returns nothing
local multiboarditem mbi = null
local integer i = 0
call MultiboardSetRowCount(udg_mb, 7)
call MultiboardSetColumnCount(udg_mb, 1) 
loop
    exitwhen i == 7
    set mbi = MultiboardGetItem(udg_mb, i, 0)
    call MultiboardSetItemStyle(mbi, false, false)
    call MultiboardReleaseItem(mbi)
    //Should I nullify mbi here?
    //set mbi = null
    set i = i+1
endloop
set mbi = null
endfunction

Is it pointless to nullify the variable inside the loop, since its getting another value after next lap?
Or should I set it to null thus it could leak?

Hm an explanantion would be nice =)
/Regards

Ps: I've seen that when blizzards creation of "preplaced units" doesn't nullify their variables iin between... But still...
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Yesyes, multiboarditem was just an example
I could take local unit u and create a new unit as well.

Anyway, nullfying once is enough I see. I had in mind that it perhaps was overwriting the variable in such a way that the memory still kept the old one.

Nice with a very quick answer =)
+rep
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Uhm, so you mean that I wouldn't do like this?
JASS:
function ResourceBoard takes nothing returns nothing
    local string array s
    local string array t
    local integer i = 0
    local integer j
    set s[0] = "ReplaceableTextures\\CommandButtons\\BTNBundleOfLumber.blp"
    set s[1] = "ReplaceableTextures\\CommandButtons\\BTNUrnOfKelThuzad.blp"
    set s[2] = "ReplaceableTextures\\CommandButtons\\BTNGatherGold.blp"
    set s[3] = "ReplaceableTextures\\CommandButtons\\BTNPotionOfRestoration.blp"
    set s[4] = "ReplaceableTextures\\CommandButtons\\BTNPhilosophersStone.blp"
    set s[5] = "ReplaceableTextures\\CommandButtons\\BTN3M3.blp"
    set s[6] = "ReplaceableTextures\\CommandButtons\\BTNChestOfGold.blp"
    set t[0] = "Wood"
    set t[1] = "Mercury"
    set t[2] = "Ore"
    set t[3] = "Sulfur"
    set t[4] = "Crystal"
    set t[5] = "Gems"
    set t[6] = "Gold"
    loop
        exitwhen i == 12
        if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
            set udg_ResourceMB[i] = CreateMultiboard()
            call MultiboardDisplay(udg_ResourceMB[i], false)
            call MultiboardSetRowCount(udg_ResourceMB[i], 7)
            call MultiboardSetColumnCount(udg_ResourceMB[i], 2)
            call MultiboardSetTitleText(udg_ResourceMB[i], "Resources")
            set j = 0
            loop
                exitwhen j == 7
                set s[j] = null // Edit: Its not right I see now
                set t[j] = null //
                set j = j+1
            endloop
        endif
        set i = i+1    
    endloop
    set mbi = null
endfunction
 
Level 17
Joined
Apr 13, 2008
Messages
1,597
Er, to tell you the truth I think string ONLY leak on very special ocassions, so you don't have to null them.
I could be wrong so let someone more experienced answer this.

But if you want to null a string array do it like this:
set s[#] = null

(you can null every kind of arrays like this)
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
^_^ didnt you look at the code?

I have 2 rows within the inner loop saying set s[#] = null (set s[j] = null)
the thing was that you said "no nulling in loops since there could be a more effective way..." So is there in my case?

Ewm, It could be something else than a string, like a handle as example...
 
Level 17
Joined
Apr 13, 2008
Messages
1,597
Um, I didn't read the whole code, just the commented rows, but I think you misunderstood.
When you write
s[#] then you refer to EVERY index in that array with the "#" character. # is not a number, that's how you write it.
"set [#] = null" = set the WHOLE array to null.
I hope that's a little clearer.
But I still think that strings should not be nulled since they are automatically nulled at the end of the trigger / function. I'll look into it a little later if noone confirms that.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Oh I see. Yup didnt understand that

Thanks :D

Oh and I saw a flaw in my code... I nullified the strings before all users got them on the leaderboard... -.-

Edit: set s[#] = null at the end of the code didnt work. it says unrecognized character: #
help is appreciated
 
Last edited:
Level 11
Joined
Feb 18, 2004
Messages
394
... the _only_ type(s) you have to null are normally allocated handles.

These include:
group, unit, force, location

These do NOT include:
player, anything that uses a function named "GetConverted_____(int)", the types that are not descended from the handle type: string code boolean integer real


Neither is a complete list.

You only need to null local variables. (That does _NOT_ include a functions parameters. You do NOT need to null parameters.) You do not need to null local variables which will only ever hold a value that will never be destroyed. (Eg: The player(s) hero(es) in an arena or AOS style map.) It is still considered good practise to null them anyway.

You only need to null local variables before a function goes out of scope. (Meaning when a function returns. Consider there to be an implicit "return" statement at the end of functions which return nothing.)

set s[#] = null is just stupid and not valid JASS... to set each item in an array to null, you have to iterate (loop) over it. (Which means you also need to know how many items are in an array. Just FYI, the array size 'limit' in JASS is 8191. (all arrays can be considered this size. There are no "smaller" arrays, but each array only uses the memory required for the indexes which are used in it.)
 
Status
Not open for further replies.
Top