How necessary is "null" the variables?

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
[code=jass] - Integer Question

You don't need to null Integers and Reals. I may be forgetting some.

You do need to null Groups, Forces, Units, Points (Locations), etc... AFTER removing/destroying them.

I think you get an error in vJass if you try to null something that shouldn't be nulled.
 

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
I heard that, but I mean when some people who seem to know about the topic do not do this with that things, are they doing it wrong?, and Have I do this also with global variables and in GUI?
You only null local variables, and you need to do it in GUI as well.

Global variables will always have some value.
 

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
Oh thank you, and one more question: I heard I have to avoid the "Do nothing" function, but I have to use it if I use the "If/Then/Else"(One action) function, Is it necessary?
You can use:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • Then - Actions
    • Else - Actions
And no, it does nothing. I think it was needed a while back in the early days of wc3.

I really can't confirm or deny whether it's actually a bad thing.
 
Level 20
Joined
Jun 26, 2020
Messages
1,576
You can use:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • Then - Actions
    • Else - Actions
And no, it does nothing. I think it was needed a while back in the early days of wc3.

I really can't confirm or deny whether it's actually a bad thing.
I know I can do that, but that will make my trigger look less elegant, when I ask Is it necessary? I mean Is it necessary avoid that function?
 
Level 20
Joined
Apr 12, 2018
Messages
496
Do Nothing was necessary to complete an If-Then-Else function which you could only do one Action or Condition on them back during RoC (every section had to be filled with something, hence where Do Nothing comes in). TFT introduced the Multi version so it's no longer necessary.

And really it doesn't do anything, it doesn't matter if its there or not unless you're really that particular about not 'wasting' a process.
 
Level 1
Joined
Apr 8, 2020
Messages
110
They could have filled the else part with comments, so Do Nothing wasn't necessary back then. It is just that they did not realize this hehe.
 

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
You only null local variables. So yes, you're doing it correctly there.

"local unit u" would exist forever in the game's memory if it wasn't nulled.

udg_Temp_Unit, a global variable, is intended to exist forever, so it doesn't need the same treatment.
  • Example
    • Events
      • Unit - A unit enters (Entire map)
    • Conditions
    • Actions
      • Custom script: local unit u
      • Custom script: set u = GetTriggerUnit()
      • Custom script: set udg_Unit = u
      • Custom script: set u = null
      • Game - Display to (All players) for 30.00 seconds the text: (Name of Unit)
Using this trigger as an example:
I set u = the entering unit and I set udg_Unit = the entering unit.
I then null u and display the name of udg_Unit.
udg_Unit is pointing to the entering unit, not u, and will display the unit's name properly.
u has been successfully cleaned up and will return null.
 
Level 20
Joined
Jun 26, 2020
Messages
1,576
Memory Leaks Again, this tutorial explains it all.
But yes, only agents need to be nulled (local variables only), you don't null strings, they will always leak, but once. Meaning that once a character is in the string table it won't leak anymore.
Oh I miss the word "agent", thank you.
If someone wanna know these aren't agents:
vJASS:
igamestate
image
itempool
itemtype
lightning
limitop
mapcontrol
mapdensity
mapflag
mapsetting
mapvisibility
pathingtype
placement
playercolor
playerevent
playergameresult
playerscore
playerslotstate
playerstate
playerunitevent
race
racepreference
raritycontrol
soundtype
startlocprio
terraindeformation
texmapflags
texttag
triggeraction
triggercondition
ubersplat
unitevent
unitpool
unitstate
unittype
version
volumegroup
weapontype
weathereffect
widgetevent
 
There are more missing. All primitives, enums and handles that are not listed unter 'agent' are not agents JASS Manual: API Browser - Type handle.

1620557095340.png


It's easier to say what IS an agent, looking at JASS Manual: API Browser - Type agent.
 
Top