im trying to make an orbit function, and this is how im doing it, i made a perioic timer in the original Actions function and have it execute this every 0.02 seconds.
but for some reason this function leaks and i dont know why. and yes im sure it leaks becuase after a few mins of running wc3 the mem usage in task manager is sky high.
Help!
function Generator_Orbit takes nothing returns nothing
local timer t=GetExpiredTimer()
local unit caster=GetCaster(t)
local real orbitangle=GetOrbitAngle(t)
local unit generator=GetGenerator(t)
local real x
local real y
set x=200*CosBJ(2*orbitangle)
set y=200*SinBJ(2*orbitangle)
call SetUnitX(generator, GetUnitX(caster)+x)
call SetUnitY(generator,GetUnitY(caster)+y)
if orbitangle==360 then
set orbitangle=0
else
set orbitangle=orbitangle+1
endif
call SetHandleReal(t,"orbitangle",orbitangle)
set t=null
set caster=null
set generator=null
endfunction
Don't forget that if you remove the expired, you should call this first: call FlushHandleLocals(t) The references are left behind in memory unless you flush them.
you dont understand, the leak is occuring if i just call GetHandleHandle, regardless if i use call flushhandlelocals in that trigger or not, simply using GetHandleHandle is causing a leak.
You are right. I did some tests on this and I found out that the problem is InitGameCache. When people started using the gamecache someone convinced me that it didn't leak - but it does! It returns a new handle every time and those handles leak. To fix it, make a global Gamecache variable and initialize it at map initialization. In the function called LocalVars, make it return that variable and it won't leak anymore.
i got another problem i need help with though this function also leaks
function GetEnemy takes unit caster, location origin, real range returns unit
local unit tempunit
local group all=CreateGroup()
set bj_wantDestroyGroup=true
set all=GetUnitsInRangeOfLocAll( range, origin)
set bj_wantDestroyGroup=true
loop
set tempunit=FirstOfGroup(all)
exitwhen tempunit==null
if IsUnitEnemy(tempunit, GetOwningPlayer(caster)) and IsUnitAliveBJ(tempunit) then
call DestroyGroup(all)
set all=null
//set tempunit=null
return tempunit
else
call GroupRemoveUnitSimple(tempunit, all)
endif
endloop
call DestroyGroup(all)
set all=null
set tempunit=null
return null
endfunction
any idea why? i dont think the location in the argument should leak, maybe it does????