- Joined
- Dec 31, 2006
- Messages
- 2,216
When you create locations, units, destructables, items etc, they take up memory, and if you don't remove these when you're done with them then you will get a memory leak, and eventually all your memory will be taken and wc3 will crash or freeze.
That is why it's important to null local variables. I hope that was easy enough to understand. There are a few more complex reasons as well.
Edit: Example of leak:
And this is how you remove it:
Not only did I remove the location, but I nulled the variable pointing to it, which means that function is now leakless. If I had not nulled it, but just removed it, it would've still leaked, and the same if I had only nulled it and not removed it. The latter leaks the most, btw.
That is why it's important to null local variables. I hope that was easy enough to understand. There are a few more complex reasons as well.
Edit: Example of leak:
JASS:
function Leak takes nothing returns nothing
local location loc = Location(0,0)
call CreateUnitAtLoc(Player(0), 'hfoo', loc, 0)
endfunction
And this is how you remove it:
JASS:
function Leak takes nothing returns nothing
local location loc = Location(0,0)
call CreateUnitAtLoc(Player(0), 'hfoo', loc, 0)
call RemoveLocation(loc)
set loc = null
endfunction
Not only did I remove the location, but I nulled the variable pointing to it, which means that function is now leakless. If I had not nulled it, but just removed it, it would've still leaked, and the same if I had only nulled it and not removed it. The latter leaks the most, btw.