Possible Mem Leak

Reaction score
65
This trigger lags. My quess is that there is a memory leak. Could someone fix it?
Code:
Time - Every 0.05 seconds of game time
Set Tanks = (Units of type Tank Crew)
Unit Group - Pick every unit in Tanks and do (Actions)
    Loop - Actions
        Set TankMovePoint = (Position of (Picked unit))
        Set TankMovePoint2 = (TankMovePoint offset by 33.00 towards (Facing of (Picked unit)) degrees)
        Unit - Order (Picked unit) to Move To TankMovePoint2
        Custom script: call RemoveLocation (udg_TankMovePoint)
        Custom script: call RemoveLocation (udg_TankMovePoint2)
Custom script: call DestroyGroup (udg_Tanks)
 

lh2705

Just another Helper
Reaction score
111
edit...
not sure whether it causes leaks or not but i always nvr set variables for position of picked units..

lag might be because of the custom scripts in the loops
 

Ozzdog

Hopeless Toby Driver fan boy
Reaction score
65
I believe that when you:

Code:
Unit Group - Pick every unit in Tanks and do (Actions)

it causes a memory leak (causing lag), and since this happens every 0.05 seconds, thats alot of lag!
 
Reaction score
65
lh2705, your first suggestion (that you edited out) didn't help. And to your second one, doesn't every point that isn't removed cause a mem leak?
Ozzdog, I had a look at some tutorials, and seems like "pick every unit in..." triggers are supposed to be done like that.
Any more suggestions?
 
Reaction score
65
Any idea why it lags then? There are only 10 units that are moved by this trigger, so that shouldn't be it. And yes, it should be this trigger, when I turn it off, there is absolutely no lag.
 
Reaction score
65
Ehem. It isn't. It only applies to 10 units, while a longer (and with shorter intervals) trigger of mine moves applies to dozens of units at most, causing no lag. Note that the lag caused by this trigger builds up, meaning that at start it doesn't lag but in the end it does.
 

SFilip

Gone but not forgotten
Reaction score
633
there is a...rather small (but "deadly" in this case) memory leak that involves the use of a BJ function.
BJ functions are JASS functions made in jass and are used by almost all GUI triggers. sometimes they can be useful - in this case (Units of type Tank Crew) is actually a BJ that picks all units and then filters them out...this causes a memory leak that was probably unknown to blizzard - not nulling handle locals.
the only way to fix this would be to perhaps convert the trigger to jass and assign the group using natives...or alternatevly to pick all units and filter them out yourself (if unit type of picked unit equals to Tank Crew then ...)
 
Reaction score
65
Hmmm... I was still unable to completely remove the lag :eek:. Could someone fix it (can involve changing it to JASS)?
 
I

iNsaNe

Guest
Geelottaja said:
Hmmm... I was still unable to completely remove the lag :eek:. Could someone fix it (can involve changing it to JASS)?
just go to edit - Convert To Custom Text

copy and paste the first line of the unit group part (it's easy to tell what you want and I'm not even good in JASS),
hit ctrl z so you get back to GUI, paste that line into the GUI custom script option, Convert To Custom Text and repeat, etc.
 

SFilip

Gone but not forgotten
Reaction score
633
ok this seems to work although i didn't have enough time to test it.
Code:
function Trig_Untitled_Trigger_001_Func002A takes nothing returns nothing
    local location TankMovePoint = GetUnitLoc(GetEnumUnit())
    local location TankMovePoint2 = PolarProjectionBJ(TankMovePoint, 33., GetUnitFacing(GetEnumUnit()))
    call RemoveLocation(TankMovePoint)
    call IssuePointOrderLoc(GetEnumUnit(), "move", TankMovePoint2)
    call RemoveLocation(TankMovePoint2)
    set TankMovePoint = null
    set TankMovePoint2 = null
endfunction

constant function Trig_Untitled_Trigger_001_TypeCond takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == [COLOR=Red][B]'hfoo'[/B][/COLOR]
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local group Tanks = CreateGroup()
    local group TmpGroup = CreateGroup()
    local boolexpr Cond = Condition(function Trig_Untitled_Trigger_001_TypeCond)
    local integer index = 0
    loop
        call GroupClear(TmpGroup)
        call GroupEnumUnitsOfPlayer(TmpGroup, Player(index), Cond)
        call GroupAddGroup(TmpGroup, Tanks)
        set index = index + 1
        exitwhen index == 16
    endloop
    call DestroyGroup(TmpGroup)
    call ForGroup(Tanks, function Trig_Untitled_Trigger_001_Func002A)
    call DestroyGroup(Tanks)
    call DestroyBoolExpr(Cond)
    set Tanks = null
    set TmpGroup = null
    set Cond = null
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_Untitled_Trigger_001, .05, true)
    call TriggerAddAction(gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions)
endfunction
put this code in notepad, press Ctrl+H and replace Untitled_Trigger_001 in this trigger with your trigger's name (in it use _ instead of spaces).
then convert the trigger in the world editor to custom text and replace the code you get with this.
also you need to replace the footman order id hfoo (makred red in the code) with the id of your tank unit. to find out which id your unit uses open the object editor and find it. then press Ctrl+D and its name will be replaces with something like this if its custom abcd:a000. what you need is the 4 chars after :, replace hfoo with them.
hopefully it wont lag :p
 

SFilip

Gone but not forgotten
Reaction score
633
send me your map via pm and i'll implement it for you.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top