• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Looking for someone experienced with memory leaks

Status
Not open for further replies.
Level 8
Joined
Jul 29, 2010
Messages
319
Hi, just wondering if anyone would be willing to help me go through each of my triggers 1 by 1 to help me find and fix any leaks that may be present? As far as my knowledge goes of memory leaks there are a quite a few of these triggers that don't leak since they don't use any of the known "leaky" actions, however there are a decent number of triggers that DO use actions that I think leak and would seriously appreciate the help in fixing them since I'm incredibly close to being able to release a beta/test map.
If anyone is willing to pick up the challenge then I'm grateful, triggers will be posted below.

To clarify, my map is a TD.

Trigger 1 - Setting Variables
  • Variables
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Game - Display to (All players) the text: |c006969FFCreating ...
      • Player Group - Pick every player in (All enemies of Player 21 (Coal)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) slot status) Equal to Is playing
            • Then - Actions
              • Player Group - Add (Picked player) to Players
            • Else - Actions
      • Set NumberOfPlayers = (Number of players in Players)
      • Set CurrentWaveNum = 0
      • Set InitialPrepRound = 60.00
      • Set GoldPerKill = 2
      • Set UnitParameters1 = 1
      • Set UnitParameters2 = 4
      • Set ParameterIncrement = 2
      • Set GoldPerWave = 60
      • Set NumberOfLives = (30 x (Number of players in Players))
      • Hashtable - Create a hashtable
      • Set RegionsHashtable = (Last created hashtable)
      • -------- Lane 1 --------
      • Hashtable - Save Handle OfLane1Spawn1 <gen> as 1 of 1 in RegionsHashtable
      • Hashtable - Save Handle OfLane1Spawn2 <gen> as 2 of 1 in RegionsHashtable
      • -------- Lane 2 --------
      • Hashtable - Save Handle OfLane2Spawn1 <gen> as 1 of 2 in RegionsHashtable
      • Hashtable - Save Handle OfLane2Spawn2 <gen> as 2 of 2 in RegionsHashtable
      • -------- Lane 3 --------
      • Hashtable - Save Handle OfLane3Spawn1 <gen> as 1 of 3 in RegionsHashtable
      • Hashtable - Save Handle OfLane3Spawn2 <gen> as 2 of 3 in RegionsHashtable
      • -------- Lane 4 --------
      • Hashtable - Save Handle OfLane4Spawn1 <gen> as 1 of 4 in RegionsHashtable
      • Hashtable - Save Handle OfLane4Spawn2 <gen> as 2 of 4 in RegionsHashtable
      • -------- Lane 5 --------
      • Hashtable - Save Handle OfLane5Spawn1 <gen> as 1 of 5 in RegionsHashtable
      • Hashtable - Save Handle OfLane5Spawn2 <gen> as 2 of 5 in RegionsHashtable
      • -------- Lane 6 --------
      • Hashtable - Save Handle OfLane6Spawn1 <gen> as 1 of 6 in RegionsHashtable
      • Hashtable - Save Handle OfLane6Spawn2 <gen> as 2 of 6 in RegionsHashtable
      • -------- Lane 7 --------
      • Hashtable - Save Handle OfLane7Spawn1 <gen> as 1 of 7 in RegionsHashtable
      • Hashtable - Save Handle OfLane7Spawn2 <gen> as 2 of 7 in RegionsHashtable
      • -------- Lane 8 --------
      • Hashtable - Save Handle OfLane8Spawn1 <gen> as 1 of 8 in RegionsHashtable
      • Hashtable - Save Handle OfLane8Spawn2 <gen> as 2 of 8 in RegionsHashtable
      • Set DialogTitleString = Ready Up!
      • Set ShowIngameTriggerData = False
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ShowIngameTriggerData Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: (String(NumberOfPlayers))
          • Game - Display to (All players) the text: |c006969FFFinished ...
        • Else - Actions
      • Trigger - Run Event <gen> (checking conditions)
      • Trigger - Run Infomation <gen> (checking conditions)
      • Trigger - Run UnitTypes <gen> (checking conditions)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility across (Playable map area)
Trigger 2 - Camera control
  • Zoom Out
    • Events
      • Player - Player 1 (Red) types a chat message containing -cam as A substring
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Substring((Entered chat string), 1, 4)) Equal to -cam
        • Then - Actions
          • Set SubStringInteger = ((Integer((Substring((Entered chat string), 5, 6)))) x 1000)
          • Camera - Set (Triggering player)'s camera Distance to target to (Real(SubStringInteger)) over 0.50 seconds
        • Else - Actions
Trigger 3 - Removing escaped units
  • UnitEntersFinalRegion
    • Events
      • Unit - A unit enters Final <gen>
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Triggering unit)) Equal to Player 21 (Coal)
        • Then - Actions
          • Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Human\MassTeleport\MassTeleportTarget.mdl
          • Unit Group - Remove (Triggering unit) from CurrentLivingUnits
          • Unit - Remove (Triggering unit) from the game
          • Set NumberOfLives = (NumberOfLives - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • NumberOfLives Greater than 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (All units of CurrentLivingUnits are dead) Equal to True
                • Then - Actions
                  • Sound - Play ArrangedTeamInvitation <gen>
                  • Unit Group - Remove all units of CurrentLivingUnits from CurrentLivingUnits
                  • Countdown Timer - Start RoundPreperationTimer as a One-shot timer that will expire in 30.00 seconds
                  • Player Group - Pick every player in (All players) and do (Actions)
                    • Loop - Actions
                      • Player - Set (Picked player) Current gold to (((Picked player) Current gold) + 300)
                • Else - Actions
            • Else - Actions
              • Player Group - Pick every player in Players and do (Actions)
                • Loop - Actions
                  • Game - Defeat (Picked player) with the message: Defeat!
        • Else - Actions
Trigger 4 - Dialog Response
  • Response
    • Events
      • Dialog - A dialog button is clicked for ReadyUp
    • Conditions
    • Actions
      • Dialog - Hide ReadyUp for (Triggering player)
      • Unit - Create 1 Builder for (Triggering player) at ((Triggering player) start location) facing 0.00 degrees
      • Unit Group - Add (Last created unit) to Builders
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Lane1Spawn <gen> contains (Last created unit)) Equal to True
        • Then - Actions
          • Set LaneBoolean[1] = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Lane2Spawn <gen> contains (Last created unit)) Equal to True
        • Then - Actions
          • Set LaneBoolean[2] = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Lane3Spawn <gen> contains (Last created unit)) Equal to True
        • Then - Actions
          • Set LaneBoolean[3] = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Lane4Spawn <gen> contains (Last created unit)) Equal to True
        • Then - Actions
          • Set LaneBoolean[4] = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Lane5Spawn <gen> contains (Last created unit)) Equal to True
        • Then - Actions
          • Set LaneBoolean[5] = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Lane6Spawn <gen> contains (Last created unit)) Equal to True
        • Then - Actions
          • Set LaneBoolean[6] = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Lane7Spawn <gen> contains (Last created unit)) Equal to True
        • Then - Actions
          • Set LaneBoolean[7] = True
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Lane8Spawn <gen> contains (Last created unit)) Equal to True
        • Then - Actions
          • Set LaneBoolean[8] = True
        • Else - Actions
Trigger 5 Selling units
  • Selling Units
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Sell
        • Then - Actions
          • Special Effect - Create a special effect attached to the overhead of (Triggering unit) using UI\Feedback\GoldCredit\GoldCredit.mdl
          • Unit - Kill (Triggering unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Ancient Protector
            • Then - Actions
              • Player - Set (Owner of (Triggering unit)) Current gold to (((Owner of (Triggering unit)) Current gold) + 144)
              • Player - Set (Owner of (Triggering unit)) Current lumber to (((Owner of (Triggering unit)) Current lumber) + 8)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Skeletal Wizard
            • Then - Actions
              • Player - Set (Owner of (Triggering unit)) Current gold to (((Owner of (Triggering unit)) Current gold) + 160)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Sorceress
            • Then - Actions
              • Player - Set (Owner of (Triggering unit)) Current gold to (((Owner of (Triggering unit)) Current gold) + 100)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Rifleman
            • Then - Actions
              • Player - Set (Owner of (Triggering unit)) Current gold to (((Owner of (Triggering unit)) Current gold) + 48)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Guard
            • Then - Actions
              • Player - Set (Owner of (Triggering unit)) Current gold to (((Owner of (Triggering unit)) Current gold) + 25)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Royal Guard
            • Then - Actions
              • Player - Set (Owner of (Triggering unit)) Current gold to (((Owner of (Triggering unit)) Current gold) + 80)
            • Else - Actions
        • Else - Actions
Trigger 6 - Relaying units
  • Relay1
    • Events
      • Unit - A unit enters Lane1Relay <gen>
      • Unit - A unit enters Lane5Relay <gen>
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Owner of (Triggering unit)) Equal to Player 21 (Coal)
        • Then - Actions
          • Unit - Order (Triggering unit) to Move To (Center of Relay1 <gen>)
        • Else - Actions
Trigger 7 - Creating Enemy units
  • Lane1
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • LaneBoolean[1] Equal to True
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SpecialWave Equal to False
            • Then - Actions
              • Unit - Create 1 UnitTypes[(Random integer number between UnitParameters1 and UnitParameters2)] for Player 21 (Coal) at (Center of (Load (Random integer number between 1 and 2) of 1 in RegionsHashtable)) facing 0.00 degrees
              • Unit Group - Add (Last created unit) to CurrentLivingUnits
              • Unit - Order (Last created unit) to Move To (Center of Lane1Relay <gen>)
              • Unit - Add Ghost (Visible) to (Last created unit)
            • Else - Actions
              • -------- SpecialWave --------
              • Unit - Create 1 UnitTypes[(Integer(Special))] for Player 21 (Coal) at (Center of (Load (Random integer number between 1 and 2) of 1 in RegionsHashtable)) facing 0.00 degrees
              • Unit Group - Add (Last created unit) to CurrentLivingUnits
              • Unit - Order (Last created unit) to Move To (Center of Lane1Relay <gen>)
              • Unit - Add Ghost (Visible) to (Last created unit)
        • Else - Actions
Trigger 8 - A unit dies
  • UnitDies
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in CurrentLivingUnits) Equal to True
        • Then - Actions
          • Player - Set (Owner of (Killing unit)) Current gold to (((Owner of (Killing unit)) Current gold) + GoldPerKill)
          • Floating Text - Create floating text that reads (|c00FFD700+ + ((String(GoldPerKill)) + |r)) above (Triggering unit) with Z offset -200.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
          • Floating Text - Set the velocity of (Last created floating text) to 300.00 towards 65.00 degrees
          • Floating Text - Change the age of (Last created floating text) to 2.00 seconds
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (All units of CurrentLivingUnits are dead) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SpecialWave Equal to True
                • Then - Actions
                  • Set SpecialWave = False
                  • Set SpecialWaveChance = 0
                • Else - Actions
              • Sound - Play ArrangedTeamInvitation <gen>
              • Player Group - Pick every player in Players and do (Actions)
                • Loop - Actions
                  • Player - Set (Picked player) Current gold to (((Picked player) Current gold) + GoldPerWave)
              • Unit Group - Remove all units of CurrentLivingUnits from CurrentLivingUnits
              • Countdown Timer - Start RoundPreperationTimer as a One-shot timer that will expire in 30.00 seconds
            • Else - Actions
        • Else - Actions
There are a few other triggers as well but they don't use commands that create units nor order them to move or anything of the sort, they're mostly just changing variables depending on ingame events so i left them out.
 
Level 13
Joined
Oct 12, 2016
Messages
769
There are memory leaks in these triggers:
1) Create a temporary player group after a temporary unit group, then remove both (at the top)
3) Remove the special effect after its creation (Destroy last created special effect)
4) Player start location needs to be made into a temp point, then removed
5) Same as 3, remove the special effect
7) Declare then remove the points used for creating the units, or preset those points at map initialization. You may need to remove the temporary region as well unless it is permanent or preset


On a side note: you do not need to remove unit groups or points that you use multiple times. It's actually more efficient that way.
 
Level 39
Joined
Feb 27, 2007
Messages
5,019
For reference: Things That Leak
  • Trigger 1: you create the "Players" group but you appear not to use it consistently later in the other triggers. A lot of things that are (All Players) should probably be Players, though that really doesn't change much. The leak Wark pointed out in 1 is "Enemies of Player 21 (Coal)" which you remove with call DestroyForce(udg_TEMPFORCE)
  • Trigger 2: fine
  • Trigger 3: In addition to leaking the SFX at the start you leak a location: (Position of (Triggering unit)). Depending on how the mass teleport model is, destroying it immediately as Wark suggested might cause it not to display anything at all. If that's the case you can save it in a GUI shadowed local variable
  • Trigger 4: nothing further
  • Trigger 5: same caveat about the effect maybe not showing up as with 3.
  • Trigger 6: Center of Relay1 <gen> leaks, but as Wark suggested instead of cleaning the point every time it's probably better to set it at map init and then just reuse the point variable every time you need to and never remove it.
  • Trigger 7: there are also point leaks in the order action. Again it would definitely be better to just store and re-use these points rather than loading a random region and getting its center point. I don't think Wark is correct that the region is a leak here, since it's just a reference to it and not actually creating new data from the hashtable (same handle ID). If I'm wrong about this someone please correct me. It seems analogous if anything to the non-nulled-local-variable-before-function-end leak. Either way, saving the points instead of regions in your hashtable would avoid this question/issue altogether.
  • Trigger 8: you leak the floating texts and I'm not sure you're properly giving them a lifetime. See this post.
Many of your gold-modifying actions can be simplified. There is a "modify property" action instead of a "set property" action, which allows you to do: Player - Add GoldPerKill to (Owner of (Killing Unit)) current gold instead of the 'set to old + additional' method you've written.
 
Status
Not open for further replies.
Top