[Solved] Fixing memory leaks prevents trigger from working...

Level 2
Joined
Oct 31, 2007
Messages
14
Hello everyone!

I made a spell via trigger that works perfectly fine (but leaks), and when I add the custom script to remove location memory leaks it stops working, like it can't find location anymore.

  • Crushing Wave
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Vague écrasante
    • Actions
      • Set VariableSet WaveCaster = (Triggering unit)
      • Set VariableSet WaveAngle = (Angle from (Position of WaveCaster) to (Target point of ability being cast))
      • Set VariableSet WavePoint = (Position of WaveCaster)
      • Set VariableSet WaveCount = 20
      • Set VariableSet WaveDamage = ((Max mana of WaveCaster) x (0.02 + (0.01 x (Real((Level of Vague écrasante for WaveCaster))))))
      • Trigger - Turn on Wave Creation <gen>
(this next trigger is turned off by default)
  • Wave Creation
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet WaveCount = (WaveCount - 1)
      • Set VariableSet WavePoint = (WavePoint offset by 25.00 towards WaveAngle degrees.)
      • Set VariableSet locx[1] = WavePoint
      • Set VariableSet locx[2] = WavePoint
      • Set VariableSet locx[3] = WavePoint
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within (100.00 + (200.00 - (10.00 x (Real(WaveCount))))) of locx[1] matching ((((Matching unit) is alive) Equal to Vrai) and (((Matching unit) belongs to an enemy of (Owner of WaveCaster).) Equal to Vrai)).) and do (Actions)
        • Loop - Actions
          • Unit - Cause WaveCaster to damage (Picked unit), dealing WaveDamage damage of attack type Spells and damage type Normal
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within (100.00 + (200.00 - (10.00 x (Real(WaveCount))))) of locx[2] matching ((((Matching unit) has buff Tornade (Aura de lenteur)) Equal to Vrai) and (((Matching unit) belongs to an enemy of (Owner of WaveCaster).) Equal to Vrai)).) and do (Actions)
        • Loop - Actions
          • Unit - Create 1 Dummy for (Owner of WaveCaster) at (Position of (Picked unit)) facing Default building facing degrees
          • Unit - Add DummyWave to (Last created unit)
          • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Picked unit)
          • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
      • Special Effect - Create a special effect at locx[3] using Objects\Spawnmodels\Naga\NagaDeath\NagaDeath.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation(udg_locx[1])
      • Custom script: call RemoveLocation(udg_locx[2])
      • Custom script: call RemoveLocation(udg_locx[3])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WaveCount Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Custom script: call RemoveLocation(udg_WavePoint)
        • Else - Actions
  • Custom script: call RemoveLocation(udg_locx[1])
  • Custom script: call RemoveLocation(udg_locx[2])
  • Custom script: call RemoveLocation(udg_locx[3])
If I turn off these 3 lines, it works great. If I leave them on it doesn't work. Thanks for your advice!
 
Last edited:
Level 2
Joined
Oct 31, 2007
Messages
14
Wow it worked thanks a bunch! +rep

Here's the change for anyone interested:

  • Wave Creation
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • [...]
      • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
      • Set VariableSet locx[1] = WavePointNew
      • Set VariableSet locx[2] = WavePointNew
      • Set VariableSet locx[3] = WavePointNew
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • WaveCount Equal to 0
    • Then - Actions
      • Trigger - Turn off (This trigger)
      • Custom script: call RemoveLocation(udg_WavePoint)
      • Custom script: call RemoveLocation(udg_WavePointNew)
    • Else - Actions
      • Set VariableSet WavePointOffset = (WavePointOffset + 25.00)
Thanks for the tut as well.
 
Last edited:
Level 14
Joined
Jun 26, 2020
Messages
1,092
Just in case, I see you are ignoring some topics
  • Set VariableSet WavePoint = (WavePoint offset by 25.00 towards WaveAngle degrees.)
You are overwriting this variable point over and over, so this is memory leak
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • WaveCount Equal to 0
    • Then - Actions
      • Trigger - Turn off (This trigger)
      • Custom script: call RemoveLocation(udg_WavePoint)
      • Custom script: call RemoveLocation(udg_WavePointNew)
    • Else - Actions
      • Set VariableSet WavePointOffset = (WavePointOffset + 25.00)
And you are only removing the point if this condition is true, not all the time you are creating a point, so this is another memory leak, in this case only the part of "Custom script: call RemoveLocation(udg_WavePointNew)" must be stay outside of the condition.

And when you are doing something like this
  • Set VariableSet WavePoint = "Somewhere"
You are creating just a reference to that location, but when you are doing something like this.
  • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
  • Set VariableSet locx[1] = WavePointNew
  • Set VariableSet locx[2] = WavePointNew
  • Set VariableSet locx[3] = WavePointNew
You are not creating a reference, you are using the same reference, basically those variables are literally the same thing, not different references for the same point, that's because when you remove some of them, you are removing all, but if you do:
  • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
  • Set VariableSet locx[1] = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
  • Set VariableSet locx[2] = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
  • Set VariableSet locx[3] = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
Now all of that points are their own thing, so remove some of them don't eliminate the rest, but I don't really understand why are you using 3 differents points instead only using WavePointNew, if you think using points causes leak, so no, use functions that create points causes leak, so you can use WavePointNew how many times you want and nothing won't happen if you remove it after use it and not overwritting it before removing it.
 
Level 2
Joined
Oct 31, 2007
Messages
14
  • Wave Creation
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet WaveCount = (WaveCount - 1)
      • Set VariableSet WavePointOffset = WavePointOffsetNew
      • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
      • Custom script: set bj_wantDestroyGroup = true
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Terrain pathing at WavePointNew of type Walkability is off) Equal to Vrai
        • Then - Actions
          • Set VariableSet WaveCount = 0
          • Special Effect - Create a special effect at WavePointNew using Objects\Spawnmodels\Naga\NagaDeath\NagaDeath.mdl
          • Special Effect - Destroy (Last created special effect)
          • Trigger - Turn off (This trigger)
          • Custom script: call RemoveLocation(udg_WavePoint)
          • Custom script: call RemoveLocation(udg_WavePointNew)
        • Else - Actions
      • Unit Group - Pick every unit in (Units within (100.00 + (200.00 - (10.00 x (Real(WaveCount))))) of WavePointNew.) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) belongs to an enemy of (Owner of WaveCaster).) Equal to Vrai
              • ((Picked unit) is alive) Equal to Vrai
            • Then - Actions
              • Unit - Cause WaveCaster to damage (Picked unit), dealing WaveDamage damage of attack type Spells and damage type Normal
            • Else - Actions
      • Custom script: call RemoveLocation(udg_WavePointNew)
      • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within (100.00 + (200.00 - (10.00 x (Real(WaveCount))))) of WavePointNew.) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) belongs to an enemy of (Owner of WaveCaster).) Equal to Vrai
              • ((Picked unit) is alive) Equal to Vrai
              • ((Picked unit) has buff Tornade (Aura de lenteur)) Equal to Vrai
            • Then - Actions
              • Unit - Create 1 Dummy for (Owner of WaveCaster) at (Position of (Picked unit)) facing Default building facing degrees
              • Unit - Add DummyWave to (Last created unit)
              • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Picked unit)
              • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_WavePointNew)
      • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
      • Special Effect - Create a special effect at WavePointNew using Objects\Spawnmodels\Naga\NagaDeath\NagaDeath.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation(udg_WavePointNew)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WaveCount Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Custom script: call RemoveLocation(udg_WavePoint)
        • Else - Actions
          • Set VariableSet WavePointOffsetNew = (WavePointOffset + 25.00)
I tweaked it with your guidance and I reckon it works fine now.

I thought it didn't at first but realized it was a different issue with some references being lost if the wave reaches an unpathable location. I added the walkability condition to cause the wave to crash prematurely if it reaches unpathable terrain (which is fine in my books).

Can you confirm it is optimized and leak-free now?
 
Level 14
Joined
Jun 26, 2020
Messages
1,092
  • Wave Creation
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet WaveCount = (WaveCount - 1)
      • Set VariableSet WavePointOffset = WavePointOffsetNew
      • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
      • Custom script: set bj_wantDestroyGroup = true
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Terrain pathing at WavePointNew of type Walkability is off) Equal to Vrai
        • Then - Actions
          • Set VariableSet WaveCount = 0
          • Special Effect - Create a special effect at WavePointNew using Objects\Spawnmodels\Naga\NagaDeath\NagaDeath.mdl
          • Special Effect - Destroy (Last created special effect)
          • Trigger - Turn off (This trigger)
          • Custom script: call RemoveLocation(udg_WavePoint)
          • Custom script: call RemoveLocation(udg_WavePointNew)
        • Else - Actions
      • Unit Group - Pick every unit in (Units within (100.00 + (200.00 - (10.00 x (Real(WaveCount))))) of WavePointNew.) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) belongs to an enemy of (Owner of WaveCaster).) Equal to Vrai
              • ((Picked unit) is alive) Equal to Vrai
            • Then - Actions
              • Unit - Cause WaveCaster to damage (Picked unit), dealing WaveDamage damage of attack type Spells and damage type Normal
            • Else - Actions
      • Custom script: call RemoveLocation(udg_WavePointNew)
      • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within (100.00 + (200.00 - (10.00 x (Real(WaveCount))))) of WavePointNew.) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) belongs to an enemy of (Owner of WaveCaster).) Equal to Vrai
              • ((Picked unit) is alive) Equal to Vrai
              • ((Picked unit) has buff Tornade (Aura de lenteur)) Equal to Vrai
            • Then - Actions
              • Unit - Create 1 Dummy for (Owner of WaveCaster) at (Position of (Picked unit)) facing Default building facing degrees
              • Unit - Add DummyWave to (Last created unit)
              • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Picked unit)
              • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_WavePointNew)
      • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
      • Special Effect - Create a special effect at WavePointNew using Objects\Spawnmodels\Naga\NagaDeath\NagaDeath.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation(udg_WavePointNew)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WaveCount Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Custom script: call RemoveLocation(udg_WavePoint)
        • Else - Actions
          • Set VariableSet WavePointOffsetNew = (WavePointOffset + 25.00)
I tweaked it with your guidance and I reckon it works fine now.

I thought it didn't at first but realized it was a different issue with some references being lost if the wave reaches an unpathable location. I added the walkability condition to cause the wave to crash prematurely if it reaches unpathable terrain (which is fine in my books).

Can you confirm it is optimized and leak-free now?
I think it is ok, but
  • Set VariableSet WavePointNew = (WavePoint offset by WavePointOffset towards WaveAngle degrees.)
  • Custom script: call RemoveLocation(udg_WavePointNew)
Why are you doing this 3 times? I told you using FUNCTIONS that create points leak, using VARIABLE points doesn't leak because you are not creating a point when you use them, doing that once is enough.
 
Level 2
Joined
Oct 31, 2007
Messages
14
I thought this leaked a UnitGroup AND a location.
  • Unit Group - Pick every unit in (Units within (100.00 + (200.00 - (10.00 x (Real(WaveCount))))) of WavePointNew.) and do (Actions)
I get it now. Thanks for the help I'll mark it as solved now.
 
Level 14
Joined
Jun 26, 2020
Messages
1,092
I thought this leaked a UnitGroup AND a location.
  • Unit Group - Pick every unit in (Units within (100.00 + (200.00 - (10.00 x (Real(WaveCount))))) of WavePointNew.) and do (Actions)
I get it now. Thanks for the help I'll mark it as solved now.
You are welcome, and yes, unit groups also leak, but you are using "set bj_wantDestroyGroup=true" so there is no problem, just in case, with this you have to do it before every time you use "Pick every unit in..." but just in that case, if you use a unit group in another way like in a condition.
  • (Number of units in "Group function") Equal to 1
You yes or yes must do:
  • Set Temp_Group = "Group function"
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of units in Temp_Group) Equal to 1
    • Then - Actions
    • Else - Actions
  • Custom script: call DestroyGroup(udg_Temp_Group)
 
Top