Wc3C.net Does the use of this function DistanceBetweenPoints cause memery leak?
 Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar

 04-20-2017, 04:17 AM #1 yeeboys User   Join Date: Oct 2013 Posts: 19 Does the use of this function DistanceBetweenPoints cause memery leak? this is a function in BJ. JASS:```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. JASS:```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.
04-20-2017, 07:16 AM   #2
Fledermaus
default string

Join Date: May 2006
Posts: 705

Submissions (1)

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:
JASS:
```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
```
Attached Files
 Leak Test.w3x (8.6 KB, 11 views)

Last edited by Fledermaus : 04-26-2017 at 12:52 AM.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off

All times are GMT. The time now is 10:15 PM.

 -- Night Elf -- Tauren -- Troll -- Pandaren -- Underworld -- Blood Elf -- Northrend -- Lightning ---- Light-ning -- Arcane -- Diablo III -- Protoss -- Mobile Version Wc3campaigns - Archive - Top

 Affiliates