HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help understanding memory leaks

11-30-2004, 08:49 PM#1
Sicknesslife
Hello,


In the map that i am creating I have units spawned at 5 second intervals, as i understand it if you do not nullify anything dynamically created and referenced it will leak.

so if I create a Group G I would later have to DestroyGroup(G)
but what if I have a preplaced Region using the GUI editor, and create a unit there then send it to fight

I have set: TempUnit = LastCreatedUnit
then sent it to fight and set TempUnit = Null

I thought this would be enough but there is still lag, my spawn code is:

Code:
function Trig_Creeps_Actions takes nothing returns nothing
    call CreateNUnitsAtLocFacingLocBJ( 1, 'ogru', Player(0), GetRectCenter(gg_rct_Player1Creeps), GetRectCenter(gg_rct_Player2Creeps) )
    set udg_TempUnit = GetLastCreatedUnit()
    call IssuePointOrderLocBJ( udg_TempUnit, "attack", GetRectCenter(gg_rct_Player2Creeps) )
    set udg_TempUnit = null
    call TriggerSleepAction( 0.10 )
    call CreateNUnitsAtLocFacingLocBJ( 1, 'earc', Player(1), GetRectCenter(gg_rct_Player2Creeps), GetRectCenter(gg_rct_Player1Creeps) )
    set udg_TempUnit = GetLastCreatedUnit()
    call IssuePointOrderLocBJ( udg_TempUnit, "attack", GetRectCenter(gg_rct_Player1Creeps) )
    set udg_TempUnit = null
    call CreateNUnitsAtLocFacingLocBJ( 1, 'ugho', Player(1), GetRectCenter(gg_rct_Player2Creeps), GetRectCenter(gg_rct_Player1Creeps) )
    set udg_TempUnit = GetLastCreatedUnit()
    call IssuePointOrderLocBJ( udg_TempUnit, "attack", GetRectCenter(gg_rct_Player1Creeps) )
    set udg_TempUnit = null
endfunction

//===========================================================================
function InitTrig_Creeps takes nothing returns nothing
    set gg_trg_Creeps = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Creeps, 5.00 )
    call TriggerAddAction( gg_trg_Creeps, function Trig_Creeps_Actions )
endfunction

does anyone know what is leaking or can someone help me understand the nature and cause of memory leaks in JASS, it would be much appreciated. Thank you for viewing and your consideration
12-01-2004, 12:02 AM#2
curi
for one thing, u can do

set tempunit = CreateUnitAtLoc(input) (because the unit creation functions all return!)

or just:
call CreateUnitAtLoc(input) (the common.j function is faster, which might matter with lots of spawning)

for another, setting a variable to point to a unit, then nulling that variable ... does nothing. any lag is just from the units themselves. maybe removing them from the game after they die would fix it?

oh lol, looking more carefully... this lags:

GetRectCenter(gg_rct_Player1Creeps)

this *creates* a point. what you want to do is find the point once, save it in a variable, then use the variable.
12-01-2004, 01:22 AM#3
Sicknesslife
So I want to create the point once with a handle and just use the handle to reference it?

local Point Spawn1 = GetRectCenter(gg_rct_Player1Creeps)

then late

CreatUnit(....,Spawn1,)

that would stop the lag?
12-01-2004, 02:39 AM#4
a thing
1. I think you want "loaction" instead of "Point" ;)

2. Yes it leaks since you never destroyed the location with the function RemoveLocation.
12-03-2004, 08:41 AM#5
Luzif3r
btw not jass itself is causing the leaks. gui also creates leaks.
12-03-2004, 03:46 PM#6
Vexorian
GUI is just JASS with some click environment made to help you by making things difficult.

To understand a memory leak you'd rather try this comparission:
Code:
if GetUnitLoc(GetTriggerUnit())==GetUnitLoc(GetTriggerUnit()) then
    call BJDebugMsg("they are the same")
else
    call BJDebugMsg("they are not the same")
endif