Don't null globals.
Null locals all the time.
^Fundamental Rule.
Of course, we have exceptions.
In vJASS structs, we null the struct members in case they don't get overwritten.
(Because they're arrays, the data can pile up)
edit
Let me explain it to you.
Globals variables are present throughout the game.
Their memory locations are constant. They can be overwritten. Nulling them will not make a difference because they will get overwritten again.
Local variables are only present in the scope of the currently executing function.
When you declare a local unit, it's going to point to memory location A for example.
If you give it a value, that value will be found in memory location A.
When the function executes another time, the local unit will point to an empty memory location, meaning not A, but B.
If you give it a value, that value will be found in memory location B.
See? They're just being written to memory and remaining there.
Nothing is removing them.
With globals, it's perfectly fine, because global A will always point to memory location Q all game.
You don't need to null it.
Locals need to be nulled, else that unit will remain in memory forever.
There's also one side-effect.
If a unit is still referenced in memory, it's handle Id will not be recycled.
Meaning that handle Ids will be incredibly high and get higher throughout the game.
This is why you need to null locals.
Globals are overwritten and don't need to be nulled.
The only time globals should be nulled is when they're arrays.
No one really cares for this though, because when they are arrays, they still get overwritten later.
(Spell data is a good example)
In vJASS, we always null non-static struct members.
I hope this explains it.
edit
If I will approve this, I have to give it a bare-minimum rating.
But it has to be perfect, so, tip:
- Don't null the caster.
- Store the last created unit in a TempUnit variable and use that variable instead of repeating (Last created unit) 3 times.