HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

About leaking locals

03-12-2007, 11:29 PM#1
StockBreak
Hi, I have just a very fast question!
If I have a trigger like this:

Collapse JASS:
local player      p = null
local integer index = 1

loop
    set p = GetOwningPlayer( udg_Unit[ index ] )
    call DoSomething( ... )
endloop

set p = null

When I give a new value to the variable p, do I have to nullify it before using the new value or nullifying it at the end is enough?
Do I have to write the following?

Collapse JASS:
local player      p = null
local integer index = 1

loop
    set p = GetOwningPlayer( udg_Unit[ index ] )
    call DoSomething( ... )
    set p = null
endloop

set p = null

Thanks!
03-12-2007, 11:32 PM#2
Earth-Fury
http://wc3campaigns.net/showthread.php?t=81872
The tutorial link in my sig and the main page is not jsut for show ;)
03-12-2007, 11:34 PM#3
TaintedReality
The first block of code is correct, you only have to nullify it once at the end.
03-13-2007, 12:11 PM#4
StockBreak
Quote:
Originally Posted by PipeDream
Note that it does not matter that you set the variable to null, only that you change its value. Thus, a global var does not need to be nulled, as it will soon be changed which has the same effect as nullification.
This quote is my answer, right?
Thank you both!
03-13-2007, 01:27 PM#5
blu_da_noob
You don't need to null player variables.
03-13-2007, 01:39 PM#6
Earth-Fury
Quote:
Originally Posted by StockBreak
This quote is my answer, right?

Quote:
Originally Posted by The tutorial I linked to
Whenever something is never going to be destroyed, you do not need to worry about this bug. For example, in an AoS map, the heroes will likely never be removed, so setting to null will not fix any leak. Similarly, multiboards aren't likely to be and players can't be destroyed.

Try to read more thoroughly next time ;)
03-13-2007, 02:37 PM#7
DioD
player is constant function
player(0) == player(0)

its like boolexpr and some other types, same arguments cause same return value.

to check need value to be nulled or not compare it to it self

location(0,0) != location(0,0)
soo this type have to be removed\nulled
03-13-2007, 06:10 PM#8
StockBreak
Thank you all guys, actually I read all the articles/posts and I was trying to set up my mind with some basic "rules":

1) "One time" local handles variables should be nullified (so heroes/players does not, right?);
2) Changing the value of a variable = nullifing it (but you need to nullify it at the end if it is local, right?);
2) Global variables don't need to be nullified;
2) If a handle is used during a function call, for example

Collapse JASS:
call Function( GetTriggerUnit(  ) )

then the GetTriggerUnit doesn't need to be nullified using a new local variable since it doesn't leak, right?

Are those sentences wrong?

What about this:

Collapse JASS:
local location loc = null
local integer    i = 0

loop
    exitwhen i > 100
    set loc = Location( AnyX, AnyY )
    // do something with the new created location
    // ...
    call RemoveLocation( loc )
    set i = i + 1
endloop

set loc = null

Does it leak? Thanks!!!
03-13-2007, 07:17 PM#9
PipeDream
Sounds right and no, that won't leak.