HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Does Player variable leak?

02-10-2006, 01:38 PM#1
qwertyui
Basically when i am using a for-loop to cycle through players, and call Player(i) at every iteration, do i create leaking handles?

If it indeed leaks, then if i make it like this:
Collapse JASS:
local integer i=0
local player plr
loop
    set plr=Player(i)
    .... Do some actions with selected player ....
    set i=i+1
    exitwhen i=12
endloop
set plr=null

Will the leak go away?
02-10-2006, 02:02 PM#2
Anitarf
Setting variables to null doesn't destroy the object they point to; however, it's still neccesary with local handle variables, even if the object they point to is destroyed, they must be set to null at end of function. But that's a different kind of leak.

As for players, they are handles, but not dynamically created. When using the Player() function (or any other that returns a player), it doesn't create a new object, but use one that is created when the map starts.
02-10-2006, 03:38 PM#3
qwertyui
Whew....
Half of my triggers use for-loops for player cycling. If it leaked, it would be a MAJOR pain to rewrite :)
02-10-2006, 05:32 PM#4
qwertyui
I have a furhter question on the same topic
Suppose there is a function, which takes Player as an argument, and i don't initialise a special variable to pass it over to this function, but rather simply do:
Collapse JASS:
call func(Player(i),...arguments...)

The function itself looks like:
Collapse JASS:
function func takes Player plr, ...arguments, returns...

Do i need to set plr to null at the end of this function, so there are no leaks?

Or do i need to go something like this at the function call:
Collapse JASS:
local player plr
...
set plr= <some player-selecting code>
call func(plr,...arguments...)
set plr=null
02-10-2006, 05:36 PM#5
Vexorian
Actually Cubasis figured out a long ago that the bug with local handle variables leaking doesn't happen with arguments