HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Leak removal in custom functions...

06-25-2005, 04:09 PM#1
MindWorX
Best asked with code...
Code:
function My_Func takes location Loc1 returns nothing
    call RemoveLocation( Loc1 ) [i][color="Gray"]//Will this remove the leak cause by the other trigger?[/color][/i]
endfunction

Code:
function My_Func2 takes nothing returns nothing
    call My_Func(GetUnitLoc( GetDyingUnit() ))
endfunction
06-25-2005, 09:55 PM#2
Zoxc
Yes, it shoud remove it. But I don't think GetUnitLoc removes the GetDyingUnit() leak?
06-26-2005, 04:56 PM#3
shadow1500
in order to remove the leak u gotta save the point into a variable then use it then remove it.
Code:
function My_Func2 takes nothing returns nothing
    local location temppoint
    set temppoint = GetUnitLoc( GetDyingUnit() )
    call My_Func( temppoint )
endfunction
06-26-2005, 08:02 PM#4
MindWorX
Quote:
Originally Posted by Zoxc
Yes, it shoud remove it. But I don't think GetUnitLoc removes the GetDyingUnit() leak?
Yea, i know, it was just an example, just wanted to know if a leak-variable used as argument, will be cleaned, if the trigger i put it in, cleans it...
06-27-2005, 04:57 PM#5
oNdizZ
Quote:
Originally Posted by MindWorX
Best asked with code...
Code:
function My_Func takes location Loc1 returns nothing
    call RemoveLocation( Loc1 ) [i][color="Gray"]//Will this remove the leak cause by the other trigger?[/color][/i]
endfunction

Code:
function My_Func2 takes nothing returns nothing
    call My_Func(GetUnitLoc( GetDyingUnit() ))
endfunction


this wont really be any useful at all :/
couse what this do, is to create a location and then remove it, it wont remove the first location that you really want to clean.

Edit:


Code:
Set tempPoint = (Position of (Dying unit))
-------- Do whatever you want ie: add an effect --------
Custom script:   call RemoveLocation(udg_tempPoint)
06-27-2005, 09:41 PM#6
Anitarf
From what I know, this shouldn't leak. GetUnitLoc() creates a point object and you immediately call your function, passing it as an argument. That function then destroys the point object. The handle index of the object will not be free for recycling until it's object is destroyed (which you do in your function) and all pointers to it are set to something else (in your case, the only pointer you use is Loc1 when you use the point as an argument, and arguments are always cleared at end of function (unlike local variables))
06-27-2005, 11:04 PM#7
Vexorian
Too much confusion about what is a memory leak, what causes it and how to prevent them I can see.

first
Quote:
Code:
function My_Func takes location Loc1 returns nothing
    call RemoveLocation( Loc1 ) //Will this remove the leak cause by the other trigger?
endfunction

function My_Func2 takes nothing returns nothing
    call My_Func(GetUnitLoc( GetDyingUnit() ))
endfunction


Yes, it will work, no need to worry about handle local variable leak either since Loc1 is an argument there.

[quote]Yes, it shoud remove it. But I don't think GetUnitLoc removes the GetDyingUnit() leak?[/quote]

GetDyingUnit() doesn't leak

[quote]
in order to remove the leak u gotta save the point into a variable then use it then remove it.

[code]
function My_Func2 takes nothing returns nothing
local location temppoint
set temppoint = GetUnitLoc( GetDyingUnit() )
call My_Func( temppoint )
endfunction
[/code][/quote]

err, You are completelly wrong, because the argument was already a variable, and your attemp actually leaks because you are not setting temppoint to null.

[quote]
this wont really be any useful at all :/
couse what this do, is to create a location and then remove it, it wont remove the first location that you really want to clean.
[/quote]

Completelly wrong.

[code]
local location loc=GetUnitLoc(u)
local location loc2

set loc2=loc //THIS WON'T create a new POInT!

if (loc==loc2) then
call BJDebugMsg("They are the same thing!")
//you will be able to see that message.
endif
call RemoveLocation(loc2) //Will remove the point that is 'pointed' by loc and loc2, because it is the same point

set loc=null //these are needed to fix the leak of the Actual variables, this doesn't fix the leak of the objects that are pointed by the variables which is a different kind of leak
set loc2=null

[/code]
06-28-2005, 07:24 AM#8
MindWorX
Ahh, so when i set a Point Variable, it'll only refer to the first, it'll not create a new one... So i could actually do this:
Code:
 local location loc=GetUnitLoc(u)
 local location loc2
 local location loc3
 local location loc4
 local location loc5
 local location loc6
    set loc2=loc
    set loc3=loc2
    set loc4=loc3
    set loc5=loc4
    set loc6=loc5
    RemoveLocation(loc6) //[color="Gray"][i]This will clean all the Point-Leaks?[/i][/color]
    set loc=null
    set loc2=null
    set loc3=null
    set loc4=null
    set loc5=null
    set loc6=null
And that also means that using a Point as a Argument, it'll clean the point fine? And i wont even have to set the variable to null...?
06-28-2005, 03:17 PM#9
Vexorian
yes you are right