Clearing memory leaks on multiple units

Level 10
Joined
May 7, 2008
Messages
296
So I have an event that spawns multiple units in a certain region, however I'm not sure if this is leak proof free.

The units spawn precisely as I want them to, but few people have told me whilst playing my map that they lag sometimes.


What do you think of this code, is there any room for improvement on it?

  • [/S]
  • Invasion 1 Copy 2
    • Events
      • Time - Elapsed game time is 20.00 seconds
    • Conditions
    • Actions
      • Set VariableSet Point = (Random point in InvasionRegion <gen>)
      • Set VariableSet InvasionPoint = (Center of King Region <gen>)
      • Unit - Create 1 |cff00ff00Ghoul for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 |cff00ff00Ghoul for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 |cff00ff00Ghoul for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 |cff00ff00Ghoul for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 Meat Wagon for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 Meat Wagon for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 Gargoyle for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 Gargoyle for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 Gargoyle for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Unit - Create 1 Gargoyle for Player 9 (Gray) at Point facing Default building facing degrees
      • Unit - Order (Last created unit) to Patrol To InvasionPoint
      • Sound - Play HumanCallToArmsWhat1 <gen>
      • Game - Display to (All players) for 8.00 seconds the text: |cffd45e19Undead|r ...
      • Custom script: call RemoveLocation(udg_Point)
      • Custom script: call RemoveLocation(udg_InvasionPoint)
 
Level 13
Joined
Feb 27, 2019
Messages
330
That trigger does not leak since you set the locations to variables, thus being able to reference the locations and remove them from the game afterwards.

If you dont know, figure out what your playtesters mean with lag. Does the game generally lag, like fps decreases over time, then that sounds like leaks, Does the units walk slow and stand still before moving again? Not leaks, but rather too many commands and units for a single player. Split the units and commands between several players to solve that issue.

As a general rule aswell. If an event only triggers like 1 time during the game, the potential leaks will be minimal, compare that to a trigger that has the event - periodic event - every 0.01d secons. There is much more potential for leaks to have an effect for a trigger that runs constantly 1st every 0.01 seconds compared to a trigger that only runs once.
 
Last edited:
Level 10
Joined
May 7, 2008
Messages
296
That trigger does not leak since you set the locations to variables, thus being able to reference the locations and remove them from the game afterwards.

If you dont know, figure out what your playtesters mean with lag. Does the game generally lag, like fps decreases over time, then that sounds like leaks, Does the units walk slow and stand still before moving again? Not leaks, but rather too many commands and units for a single player. Split the units and commands between several players to solve that issue.
Thank you for the quick reply, well I had some playtesters say that it lags over time so I guess that I have leaks somewhere else.

I have like 20 or 30 more triggers that I have to check but I was generally concerned for this one since I'm using these type of triggers often on my map.

Once again, thanks!
 
Level 13
Joined
Feb 27, 2019
Messages
330
The most common leaks are units groups, locations and player groups. The most damaging ones are especially those that exist within a trigger with a periodic event or that fires a lot.

Also beware that if you make an action like this:
Unit - Create 1 Footman for Player 1 (Red) at ((Center of (Playable map area)) offset by 256.00 towards 0.00 degrees.) facing (Position of (Triggering unit))
it creates 3 points. The first point is Center of (Playable map area)) and the second point is offset from that first point with 256 and the last one is position of unit. So one should first do:
Set Point = Center of (Playable map area)
Set Point 3 = Position of (Triggering unit)
Set Point2 = Point offset by 256 towards 0.00 degrees facing Point 3
Create 1 Footman at Point2
call RemoveLocation(udg_Point)
call RemoveLocation(udg_Point2)
call RemoveLocation(udg_Point3)

Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Owner of (Picked unit)) Equal to Player 10 (Light Blue)
Then - Actions
Unit - Add Animate Dead to (Picked unit)
Else - Actions

Instead of this "Pick every unit in (Units in (Playable map area)) and do (Actions) creates a Unit Group that must be removed, if not, it will leak. That is fixed by"
Do this! -> Set TempGroup = (Units in (Playable map area)) <- This is our unit group and we have it referenced
Pick every unit in TempGroup and do (Actions)
if (Owner of (Picked unit)) = Player 10
then Do action towards (Picked unit)
else
call DestroyGroup(udg_TempGroup)
 
Last edited:
Level 10
Joined
May 7, 2008
Messages
296
The most common leaks are units groups, locations and player groups. The most damaging ones are especially those that exist within a trigger with a periodic event or that fires a lot.

Also beware that if you make an action like this:
Unit - Create 1 Footman for Player 1 (Red) at ((Center of (Playable map area)) offset by 256.00 towards 0.00 degrees.) facing (Position of (Triggering unit))
it creates 3 points. The first point is Center of (Playable map area)) and the second point is offset from that first point with 256 and the last one is position of unit. So one should first do:
Set Point = Center of (Playable map area)
Set Point 3 = Position of (Triggering unit)
Set Point2 = Point offset by 256 towards 0.00 degrees facing Point 3
Create 1 Footman at Point2
call RemoveLocation(udg_Point)
call RemoveLocation(udg_Point2)
call RemoveLocation(udg_Point3)
What if I create an unit facing default degrees, do I still have to create a variable and then destroy it afterwards? Does the example below create any leaks whatsoever?

Example:

  • Events
    • Time - Elapsed game time is 200.00 seconds
  • Conditions
  • Actions
    • Set VariableSet Point = (Random point in InvasionRegion <gen>)
    • Set VariableSet InvasionPoint = (Center of King Region <gen>)
    • Unit - Create 1 |cff00ff00Ghoul for Player 9 (Gray) at Point facing Default building facing degrees
    • Custom script: call RemoveLocation(udg_Point)
    • Custom script: call RemoveLocation(udg_InvasionPoint)
 
Level 13
Joined
Feb 27, 2019
Messages
330
facing whatever degrees is a real value. There is no location being created thus no leak since real values dont leak.

Creating a unit at a point facing a point on the other hand should be;
Set Point = (Random point in InvasionRegion <gen>)
Set Point 2 = (Center of King Region <gen>)
Unit - Create 1 Ghoul for Player 9 (Gray) at Point facing Point2
call RemoveLocation(udg_Point)
call RemoveLocation(udg_Point2)
 
Last edited:
Top