Does the use of this function DistanceBetweenPoints cause memery leak?
this is a function in BJ.
function DistanceBetweenPoints takes location locA, location locB returns real local real dx = GetLocationX(locB) - GetLocationX(locA) local real dy = GetLocationY(locB) - GetLocationY(locA) return SquareRoot(dx * dx + dy * dy) endfunction
this is a Custom function.
function func1 takes nothing returns nothing local location A = GetUnitLoc(unit_a) local location B = GetUnitLoc(unit_b) local real dist = DistanceBetweenPoints(A,B) call RemoveLocation(A) call RemoveLocation(B) set A = null set B = null endfunction
Does the use of this function DistanceBetweenPoints cause memery leak? Local location A and B was removed at func1. But location locA and locB wasn't removed at DistanceBetweenPoints.
No it doesn't leak because they're parameters/arguments. You only need to destroy/null local/global variables (globals don't have to be nulled because you can't ever lose the reference to that variable).
Attached a testmap so you can play around and see for yourself :)
However most people don't like using locations because they can leak.
Here are 2 commonly used alternatives:
function DistanceBetweenXY takes real x1, real y1, real x2, real y2 returns real return SquareRoot(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1))) endfunction function DistanceBetweenUnits takes unit a, unit b returns real return SquareRoot(((GetUnitX(b) - GetUnitX(a)) * (GetUnitX(b) - GetUnitX(a))) + ((GetUnitY(b) - GetUnitY(a)) * (GetUnitY(b) - GetUnitY(a)))) endfunction
|All times are GMT. The time now is 08:32 PM.|
Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services