Page 1 of 1
nulling local variables
Posted: April 30th, 2009, 9:20 pm
by storyyeller
Which variables do you have to set to null to prevent memory leaks?
I had been doing units and groups, but I saw someone else's map set local player variables to null too. Is this necessary?
Re: nulling local variables
Posted: April 30th, 2009, 10:32 pm
by Risen
Every handle except real / integer should be nulled. Special ones like groups should be DestroyGroup()'d first.
Re: nulling local variables
Posted: May 1st, 2009, 1:14 am
by storyyeller
I guess it's a good thing I don't use local players much then
Re: nulling local variables
Posted: May 1st, 2009, 9:05 pm
by Aero
storyyeller wrote:I guess it's a good thing I don't use local players much then
I use local players all the time.
Locals are much better as long as you remember to null handles.
Re: nulling local variables
Posted: May 1st, 2009, 10:21 pm
by storyyeller
No, what I mean is that I use integers to refer to the player, since even if I used actual player variables, I'd jut have to convert to an integer whenever I wanted to index an array with it anyway
E.g. stuff like this
Code: Select all
function whatever takes nothing returns nothing
local integer p = GetPlayerId(GetTriggerPlayer())
// do stuff here
endfunction
Re: nulling local variables
Posted: May 2nd, 2009, 4:30 pm
by Aero
Aha, I see. I make a lot of spells and, as you can imagine, I use a lot of unit/player variables.