- Joined
- Oct 11, 2012
- Messages
- 711
Do they leak? If not, are they efficient?
local location l = GetUnitLoc()
), it has to be nulled before the function ends.They won't if you remove it if it's no longer needed; Reals are better, unless you're manipulating the z axis.
Any location will leak if it's not removed, so use coordinated as chobibo said.
Also, when using a local location variable (local location l = GetUnitLoc()
), it has to be nulled before the function ends.
Dude try looking on the common.j (extract it from the mpq), look for all types related to agents, IIRC, all those leak references when not nulled.
local location MyLoc = GetUnitLoc ( MyUnit )
call RemoveLocation ( MyLoc )
set MyLoc = null
local real x = GetUnitX ( MyUnit )
local real y = GetUnitY ( MyUnit )
local location MyLoc = GetSpellTargetLoc ( )
call RemoveLocation ( MyLoc )
set MyLoc = null
local real x = GetSpellTargetX ( )
local real y = GetSpellTargetY ( )
Use coordinates because they're much faster than locations, coordinates does not need to remove because they're real.
GetUnitLoc:
Using Locations: Does need to remove.
Using Coordinates: Does not need to remove.JASS:local location MyLoc = GetUnitLoc ( MyUnit ) call RemoveLocation ( MyLoc ) set MyLoc = null
GetSpellTargetLoc:JASS:local real x = GetUnitX ( MyUnit ) local real y = GetUnitY ( MyUnit )
Using Locations: Does need to remove.
Using Coordinates: Does not need to remove.JASS:local location MyLoc = GetSpellTargetLoc ( ) call RemoveLocation ( MyLoc ) set MyLoc = null
JASS:local real x = GetSpellTargetX ( ) local real y = GetSpellTargetY ( )
Also, you don't need to null globals.
I ran a test, global location nulled -> no memory increase in task manager. Not nulled -> consntant increase of memory consumption.
I created/destroyed at least 100 000 locations.
Those must be reference leaks.
It's true, try it yourself when in doubt.