wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > General Development
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-20-2017, 04:17 AM   #1
yeeboys
User
 
Join Date: Oct 2013
Posts: 19

yeeboys has little to show at this moment (0)

Default Does the use of this function DistanceBetweenPoints cause memery leak?

this is a function in BJ.

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

Collapse 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.
yeeboys is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-20-2017, 07:16 AM   #2
Fledermaus
default string
 
Fledermaus's Avatar
 
Join Date: May 2006
Posts: 705

Submissions (1)

Fledermaus is a jewel in the rough (194)Fledermaus is a jewel in the rough (194)Fledermaus is a jewel in the rough (194)

Send a message via MSN to Fledermaus
Default

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:
Collapse 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
File Type: w3x Leak Test.w3x (8.6 KB, 10 views)

Last edited by Fledermaus : 04-26-2017 at 12:52 AM.
Fledermaus is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:07 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services