nulling local variables

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

storyyeller
Senior Member
Posts: 178
Joined: February 15th, 2009, 9:08 pm

nulling local variables

Post 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?
User avatar
Risen
Forum Staff
Posts: 811
Joined: January 1st, 2008, 12:58 am

Re: nulling local variables

Post by Risen »

Every handle except real / integer should be nulled. Special ones like groups should be DestroyGroup()'d first.
Image
Wanna learn to hack maps? --> Guide
storyyeller
Senior Member
Posts: 178
Joined: February 15th, 2009, 9:08 pm

Re: nulling local variables

Post by storyyeller »

I guess it's a good thing I don't use local players much then
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: nulling local variables

Post 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.
storyyeller
Senior Member
Posts: 178
Joined: February 15th, 2009, 9:08 pm

Re: nulling local variables

Post 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
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: nulling local variables

Post by Aero »

Aha, I see. I make a lot of spells and, as you can imagine, I use a lot of unit/player variables.