HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Player Variables Don't Leak?

02-26-2009, 02:00 AM#1
xombie
Collapse JASS:
local player p1 = Player(0)
local player p2 = Player(0)

If you do H2I(p1) and compare it to H2I(p2) you'll find they are the same. So. Do local player variables really leak?
02-26-2009, 02:16 AM#2
Bobo_The_Kodo
No they don't, you don't create new players ...

(You can't leak their handle ids if you never create/destroy them)
02-26-2009, 02:24 AM#3
Rising_Dusk
This means you don't have to nullify them.
02-26-2009, 02:28 AM#4
xombie
Yea, I was always nulling player variables.

xombie = FAIL

Just to be completely clear, are there any other handle types that work this way? I thought that there were two leaks, one with objects (creating/destroying) and then another with variables, for instance.

Collapse JASS:
local trigger t = CreateTrigger()

I thought that not only would the actual "trigger" created by CreatTrigger() would leak, but as would the variable t. To be a little more clear...

Collapse JASS:
local trigger t = CreateTrigger()
call DestroyTrigger(t)

Now you still have your variable, which needs to be nulled. How is it that no memory is leaked when space is allocated for the "player" variable.
02-26-2009, 02:41 AM#5
Rising_Dusk
Because the player variables function more like constant references. There are a finite number of players and whenever you declare one you 'substitute' in that reference. This means that every declaration of a given player carries the exact same value, hence an identical H2I. You can never 'create' a new player, whereas with your example you can indeed create a new trigger.
02-26-2009, 02:44 AM#6
xombie
Okay, well I suppose it won't cause me any trouble anyways, since the only tampering you really need to do with players is in actual game code.
02-26-2009, 03:05 AM#7
Earth-Fury
Player() and all the GetConverted____() functions are native equivalents of I2H()

Any type that uses such functions never need to be nulled.

I also don't think lightnighs, texttags, terraindeformations and a few other weird ones like that need to be nulled, but that's just a shot in the dark...

Oh, and boolexprs never need to be nulled. Or destroyed. (Unless you use it only once, ever. But even there, considering how buggy JASS is with destroying things, it's probably best to leave well-enough alone.)
02-26-2009, 06:35 AM#8
Ammorth
terrain deformations (atleast perm ones) are never removed, even when they are destroyed. They leak their reference and still keep their performance loss after being destroyed.

Sounds don't have to be nulled either, unless you destroy them (which you never should).
02-26-2009, 01:20 PM#9
Anitarf
You need to understand what a "variable leak" means. Each handle adress keeps a reference counter of how many variables are pointing to it. It can only get recycled for another handle if that counter is zero (and, of course, if the handle stored at that adress is destroyed). There is a bug where local variables don't properly decrement that counter at the end of a function, so we have to do it manually, else the handle index will not get recycled for a new handle once the one stored there is destroyed and you'll get handle index inflation which can degrade performance a bit. Obviously, this doesn't matter at all for handles you will never destroy, like players.
02-26-2009, 07:04 PM#10
xombie
I didn't really understand that last one.
02-26-2009, 08:13 PM#11
DioD
You dont need to null static objects.
02-26-2009, 08:20 PM#12
xombie
Alright well if I have any further questions I can always post here. Thanks for all your help.
02-27-2009, 07:32 PM#13
xombie
If player variables don't leak like that, and I do...

Collapse JASS:
local unit u1 = ...
local unit u2 = u1

Do I only need to null one of them?
02-27-2009, 07:44 PM#14
Bobo_The_Kodo
... a unit isn't a player

players cant leak because they never get destroyed, so its impossible

that would leave reference count to unit as 1, so yes it would leak
02-27-2009, 08:12 PM#15
xombie
Makes sense. Derr.