- Joined
- Jan 27, 2016
- Messages
- 89
Del
Last edited:
Incorrect. Neither example leaks. It's not using a point that leaks, it's creating it. As long as you destroy every point that you create, you'll be fine, at least in GUI. In JASS you have to also worry about nulling local variables.A]mun;2790001 said:And to give an answer, as far as i know you have to remove it after every use. So example 2 is leakless, whereas 1 does leak indeed.
local location l
set l = udg_TempPoint
//stuff
call DestroyLocation(udg_TempPoint)
Hmm, do you mean something like this?
Because yes, that will not leak. The reason it won't leak is because when you set l = TempPoint, it does not create a new point, just tells l to reference the same point that TempPoint already references.JASS:local location l set l = udg_TempPoint //stuff call DestroyLocation(udg_TempPoint)
However if you ever create a new point, then it must be destroyed.
set l = null
at the end as well.Wouldn't you leak the handle? You need to doset l = null
at the end as well.
Though, I did hear some variables don't need that (I think I heard players don't need it, but I don't remember). Are locations are like this? I'd still null them anyway lol.
widget
or ability
) needs to be nulled. However, it is kinda difficult to remember which types are agents and which are handles, so most people just null anything that isn't a primitive type (primitives: string, boolean, real, integer, code).Yes, you need to null it (also, DestroyLocation should be RemoveLocation). But EdgeOfChaos was just saying that you only need to destroy/remove the location once. Somebassoon mentions in the first post that he already nulls it.
As for the second part: local location variables need to be nulled. Any type that extends agent (or extends a type that extends agent, e.g.widget
orability
) needs to be nulled. However, it is kinda difficult to remember which types are agents and which are handles, so most people just null anything that isn't a primitive type (primitives: string, boolean, real, integer, code).
The reason why players don't need to be nulled is because players are only made once in the map and are never actually "destroyed". For objects that are permanent, we really don't care about nulling their pointers since we only null variables to ensure that their ID gets recycled when they're destroyed. This is also kinda difficult to keep track of, so it is easier to just null everything (besides primitives).