Triggers - Memory Leaks and Custom Scripts

FireBladesX

Eating my wings!
Reaction score
123
Hey, what's the difference between
TriggerOne
Every 1 seconds of game time

Set L: Random Point in Playable Map Area
Unit - create 1 Footman at L
Unit - add Last Created Unit to DoomGroup
call RemoveLocation(udg_L)


TriggerTwo
Unit casts an ability

Unit group - pick every unit in DoomGroup and do - set life of Picked Unit to (Life of Picked Unit + 100)
Unit group - clear DoomGroup


And the same, but call DestroyGroup(udg_DoomGroup)?
And, does the first one leak?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Clearing a unit group removes all units inside.
But the group is still there and can be used.

Destroying a unit group... well, destroys it.
Means it's gone.
Can't use it anymore.


With your weirdo example, "DestroyGroup" would mean that neither trigger works anymore.
 

afisakov

You can change this now in User CP.
Reaction score
37
do players leak, for instance I often refer to "triggering player" in my map, will that cause any problems if it accumulates?

Destroying a unit group... well, destroys it.
Means it's gone.
Can't use it anymore.
With your weirdo example, "DestroyGroup" would mean that neither trigger works anymore.
Is the Temp_group mentioned in the tutorial somehow different from a regular unit group, and if not then how can u clean up leaks without destroying the functionality of all ur triggers?
 
T

thewreck

Guest
New Leak

originally posted in the Leak Check thread, but i thought it was important to let you know here.

Hi. I found a new leaking trigger. Its incredibly simple, and I have no fix for it. Its not likely to affect most maps i guess, but in my map it has turned out to be crucial.

This is simply it:

TRIGGER:
Code:
ohNoes
    Events
        Unit - A unit Is issued an order targeting an object
    Conditions
    Actions

this is the JASS equivalent:
Code:
function Trig_ohNoes_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_ohNoes takes nothing returns nothing
    set gg_trg_ohNoes = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ohNoes, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddAction( gg_trg_ohNoes, function Trig_ohNoes_Actions )
endfunction

This trigger, without any actions of conditions what so ever leaks about 0.25-0.5 kb of memory each time it is fired. The best way to test it is by creating a trigger which orders a unit to do something a couple of thousand times by using a (for example):

Code:
For each (Integer A) from 1 to 3000, do (Actions)
    Loop - Actions
        Unit - Order Footman 0002 <gen> to Right-Click Footman 0000 <gen>

In my map, i use squads of units that are controlled by squad flags, thus when moving the flag, up to 20 units are ordered by triggers, thus when you have 10 flags selected, there is potentially 200 orders each time. Imagine 8 players doing this over the course of a game of an hour of say, 40 order actions per minute! Thats almost 1000 mb of memory! gah!

Without this leaking trigger, this test action does not leak a single KB.

Anyway, i have been reading through a number of leak tutorials, but so far have never read anything about this. Anyone knows what to do?
 

Artificial

Without Intelligence
Reaction score
326
It might be because TriggerRegisterAnyUnitEventBJ leaks, as it uses null as the filter. The easiest way to fix it would probably be placing these to functions to the map header:
JASS:
function SafeFilt takes nothing returns boolean
    return true
endfunction

function TriggerRegisterAnyUnitEvent takes trigger trig, playerunitevent whichEvent returns nothing
    local integer index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, Filter(function SafeFilt))
        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
endfunction
And removing the 'BJ' part of the TriggerRegisterAnyUnitEventBJ in the trigger of yours. This means you'd have to convert it to Jass, so if you prefer to work in GUI, I'd recommend you to copy the trigger of yours (while it's in GUI), disable the copy and then fix the other version. :)
 
T

thewreck

Guest
I did add your code to the header, and change the trigger to run the function without BJ. No luck. Still leaks. :(

Got any other tips, seeming as you seem to know alot about this?
 
M

mightyone

Guest
to fix memory leaks, do i need to create variables for the components of a long variable?
For example, does
Code:
Set SoK_TempUnitGroupTeam1[(Integer A)] = (Units in SoK_Windmill_Regions[(Integer A)] matching (((Matching unit) belongs to an ally of Player 1 (Red)) Equal to True))
leak? Leak check says it does, but someone told me it does not. And is
Code:
Custom script:   call DestroyGroup (udg_SoK_TempUnitGroupTeam1[(Integer A)])
how you fix the leak?
 
S

Solvent

Guest
Making my Knights do damage based on movespeed

Hey I seem to be leaking real bad can anyone spot the problem?

JASS:
Event
 A unit is attacked
Conditions
 Knight Equal to (Unit-type of (Attacking unit))
Actions
 Set Temp_Group = (Units within 0.01 of (Position of (Attacking unit)))
 Set Temp_Group2 = (Units within 0.01 of (Position of (Attacked unit)))
Unit Group - Pick every unit in Temp_Group and do (Unit - Cause (Random unit from Temp_Group) to damage (Random unit from Temp_Group2), dealing (Current movement speed of (Random unit from Temp_Group))) damage of attack type Normal and damage type Normal
Custom Script:   call DestroyGroup (udg_Temp_Group)
Custom Script:   call DestroyGroup (udg_Temp_Group2)
 

thewrongvine

The Evolved Panda Commandant
Reaction score
506
Nice, simple tut. :)

lol, chopperpope, stop spamming smilies (or spamming anything else).
 

Father_Yetti

New Member
Reaction score
46
Really helpful thanks a bunch. :D
 

simonake

New Member
Reaction score
72
Thanks alot, it's helpful for creeps spawns. But it use to need lots of variables.
Well good job. Hulk
 

Regga-Voska

New Member
Reaction score
0
Check this out!

I have read your tutorial, and im not sure that i under stand it correctly, can you please tell me if this trigger is made correct?
And if i can improve it.

Trigger:
  • Execute Move And Rotation
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group_Red = (Units owned by Player 1 (Red) of type Mortar Team)
      • Unit Group - Pick every unit in Temp_Group_Red and do (Actions)
        • Loop - Actions
          • Set Temp_Point_Red = (Position of (Picked unit))
          • Unit - Move (Picked unit) instantly to (Temp_Point_Red offset by Move_Red towards (Facing of (Picked unit)) degrees)
          • Unit - Make (Picked unit) face ((Facing of (Picked unit)) + Rotation_Red) over 0.00 seconds
          • Custom script: call RemoveLocation (udg_Temp_Point_Red)
      • Custom script: call DestroyGroup (udg_Temp_Group_Red)


BTW Great tutorial :thup:
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Put your code in between [noparse]
Trigger:
[/noparse]
tags.
Read this if you don't know how ;) .

EDIT: That's correct Regga-Voska.
Actually, you might have to put:
Code:
Temp_Point_Red offset by Move_Red towards (Facing of (Picked unit)) degrees
Into a variable too but I'm not sure.
 

vypur85

Hibernate
Reaction score
803
> I'm not sure

Yes. You have to. This whole stretch itself is a point variable:
Code:
Temp_Point_Red offset by Move_Red towards (Facing of (Picked unit)) degrees

Unleak version:
Code:
        Set Temp_Group_Red = (Units owned by Player 1 (Red) of type Mortar Team)
        Unit Group - Pick every unit in Temp_Group_Red and do (Actions)
            Loop - Actions
                Set Temp_Point_Red = (Position of (Picked unit))
                [B]Set AnotherPoint = (Temp_Point_Red offset by Move_Red towards (Facing of (Picked unit)) degrees)[/B]
                Unit - Move (Picked unit) instantly to [B]AnotherPoint[/B]
                Unit - Make (Picked unit) face ((Facing of (Picked unit)) + Rotation_Red) over 0.00 seconds
                Custom script:   call RemoveLocation (udg_Temp_Point_Red)
                [B]Custom script:   call RemoveLocation (udg_AnotherPoint)[/B]
        Custom script:   call DestroyGroup (udg_Temp_Group_Red)
 

Epicurus

New Member
Reaction score
1
What is the custom script for destroying a unit variable? Nice guide by the way, but I think it needs more destroy scripts.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top