• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] why is this simple function leaking?

Status
Not open for further replies.
Level 3
Joined
Aug 4, 2004
Messages
22
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! :)



Code:
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
 
Level 3
Joined
Aug 4, 2004
Messages
22
ive done some investigating and the leak appears to be occuring somewhere between

function GetCaster takes timer t, string s returns unit
return GetHandleHandle(t,s)
endfunction


and calling it,

local unit caster=GetCaster(t,"caster")


very strange, do the handle vars leak?
 
Level 3
Joined
Mar 27, 2004
Messages
70
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.
 
Level 3
Joined
Aug 4, 2004
Messages
22
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.
 
Level 3
Joined
Mar 27, 2004
Messages
70
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.
 
Level 3
Joined
Aug 4, 2004
Messages
22
yup, i figured that out and it works nicely now.


i got another problem i need help with though :)
this function also leaks

Code:
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???? :(
 
Level 3
Joined
Mar 27, 2004
Messages
70
The problem is here:
JASS:
local group all=CreateGroup()
set bj_wantDestroyGroup=true
set all=GetUnitsInRangeOfLocAll( range, origin)
It should look like this:
JASS:
local group all=GetUnitsInRangeOfLocAll( range, origin)
 
Status
Not open for further replies.
Top