Local location leak

Status
Not open for further replies.
Level 13
Joined
Jan 2, 2016
Messages
978
Lol, that grammar is confusing :vw_death:
If you have a local location l, and you set udg_TempPoint to l, if you remove EITHER of the 2 - you can't use that point anymore.
So remove it only after you are done using it.
Then you only need to nullify the local one.
You could null the global one too, but it's quite pointless.
 
Level 23
Joined
Dec 4, 2007
Messages
1,552
Let me try to understand this:

You want to know if you can use the temp_point multiple times:

  • Untitled Trigger
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
    • Actions
      • Set temp_point = (Position of (Triggering unit))
      • Unit - Order (Triggering unit) to Human Archmage - Blizzard temp_point
      • Unit - Order (Triggering unit) to Human Blood Mage - Flame Strike temp_point
      • Custom script: call RemoveLocation(udg_temp_point)
Or if you have to remove it after every use:

  • Untitled Trigger
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
    • Actions
      • Set temp_point = (Position of (Triggering unit))
      • Unit - Order (Triggering unit) to Human Archmage - Blizzard temp_point
      • Custom script: call RemoveLocation(udg_temp_point)
      • -------- --------
      • Set temp_point = (Position of (Triggering unit))
      • Unit - Order (Triggering unit) to Human Blood Mage - Flame Strike temp_point
      • Custom script: call RemoveLocation(udg_temp_point)

Right?

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.
 
Level 7
Joined
Oct 19, 2015
Messages
286
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.
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.
 

EdgeOfChaos

E

EdgeOfChaos

Hmm, do you mean something like this?
JASS:
local location l
set l = udg_TempPoint
//stuff
call DestroyLocation(udg_TempPoint)
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.

However if you ever create a new point, then it must be destroyed.
 
Level 12
Joined
May 22, 2015
Messages
1,051
Hmm, do you mean something like this?
JASS:
local location l
set l = udg_TempPoint
//stuff
call DestroyLocation(udg_TempPoint)
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.

However if you ever create a new point, then it must be destroyed.

Wouldn't you leak the handle? You need to do set 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.
 
Wouldn't you leak the handle? You need to do set 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.

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 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).

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).
 
Level 12
Joined
May 22, 2015
Messages
1,051
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 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).

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).

Oh I get it now. You would be nulling a handle that would still be in use, regardless. It wouldn't get recycled. The Player(i) functions would just be returning a constant handle.
 
Status
Not open for further replies.
Top