• 🏆 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!

[Spell] Two questions about removing leaks

Status
Not open for further replies.
Level 12
Joined
May 16, 2020
Messages
660
Hi guys, I have two uncertainties about removing leaks:

First, I found this trigger where the maker removes the group 2x, both within the trigger and at the end. I always thought it's enough to remove it just 1x at the end. Which one is correct?

  • Dual Breath
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Dual Breath
    • Actions
      • Set VariableSet DB_Caster = (Triggering unit)
      • Set VariableSet DB_CasterPos = (Position of DB_Caster)
      • Unit - Create 1 Dummy Unit for (Owner of DB_Caster) at DB_CasterPos facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_DB_CasterPos)
      • Unit - Add Dual Breath Dummy to (Last created unit)
      • Unit - Set level of Dual Breath Dummy for (Last created unit) to (Level of Dual Breath for DB_Caster)
      • Set VariableSet DB_TargetPos = (Target point of ability being cast)
      • Unit - Order (Last created unit) to Neutral Brewmaster - Breath Of Fire DB_TargetPos
      • Custom script: call DestroyGroup (udg_DB_Group)
      • Unit - Add a 1.50 second Generic expiration timer to (Last created unit)
      • Wait 0.27 seconds
      • Set VariableSet DB_MapCenter = (Center of (Playable map area))
      • Set VariableSet DB_Group = (Units in (Playable map area) matching (((Matching unit) has buff Dual Breath ) Equal to True))
      • Unit Group - Pick every unit in DB_Group and do (Actions)
        • Loop - Actions
          • Unit - Create 1 Dummy Unit for (Owner of DB_Caster) at DB_MapCenter facing Default building facing degrees
          • Unit - Add Dual Breath Slow to (Last created unit)
          • Unit - Set level of Dual Breath Slow for (Last created unit) to (Level of Dual Breath for DB_Caster)
          • Unit - Order (Last created unit) to Undead Lich - Frost Nova (Picked unit)
          • Unit - Add a 1.50 second Generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation (udg_DB_MapCenter)
      • Custom script: call DestroyGroup (udg_DB_Group)

Secondly, how can I avoid leaks if I cannot delete a group within a loop, because otherwise I would lose the information which is necessary for the next loop?

Take this example:

  • TimeLock Learn
    • Events
      • Unit - A unit Learns a skill
    • Conditions
      • (Learned Hero Skill) Equal to Time Lock
      • (Learned skill level) Equal to 1
    • Actions
      • Trigger - Turn on TimeLock Start again <gen>
  • TimeLock Start again
    • Events
      • Game - DamageModifierEvent becomes Equal to 1.00
    • Conditions
      • (Level of Time Lock for DamageEventSource) Greater than 0
    • Actions
      • Trigger - Turn on TimeLock Loop <gen>
      • Custom script: set udg_TimeLock_LockedUnits = CreateGroup()
      • Trigger - Turn off (This trigger)
  • TimeLock Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet TimeLock_GroupAddFreeze = (Units in (Playable map area) matching (((Matching unit) has buff Time Lock (Pause)) Equal to True))
      • Unit Group - Pick every unit in TimeLock_GroupAddFreeze and do (Actions)
        • Loop - Actions
          • Special Effect - Create a special effect attached to the chest of (Picked unit) using Abilities\Spells\Undead\AbsorbMana\AbsorbManaBirthMissile.mdl
          • Special Effect - Destroy (Last created special effect)
          • Animation - Change (Picked unit)'s animation speed to 0.00% of its original speed
          • Unit Group - Add (Picked unit) to TimeLock_LockedUnits
      • Custom script: call DestroyGroup(udg_TimeLock_GroupAddFreeze)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (TimeLock_LockedUnits is empty) Equal to True
        • Then - Actions
          • Custom script: call DestroyGroup(udg_TimeLock_LockedUnits)
          • Trigger - Turn on TimeLock Start again <gen>
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Unit Group - Pick every unit in TimeLock_LockedUnits and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) has buff Time Lock (Pause)) Equal to False
                • Then - Actions
                  • Animation - Change (Picked unit)'s animation speed to 100.00% of its original speed
                  • Unit Group - Remove (Picked unit) from TimeLock_LockedUnits.
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (TimeLock_LockedUnits is empty) Equal to True
                    • Then - Actions
                      • Custom script: call DestroyGroup(udg_TimeLock_LockedUnits)
                      • Trigger - Turn on TimeLock Start again <gen>
                      • Trigger - Turn off (This trigger)
                    • Else - Actions
If TimeLock_LockedUnits Group is NOT empty, then I'm not destroying the Group for this loop (= leak). I can't destroy it however, because then I would lose the information of this group and the affected units would be frozen forever (i.e. having animation 0).

Is there a solution for this?
 
Last edited:
1st trigger:
  • one location is created here: Set VariableSet DB_CasterPos = (Position of DB_Caster)
  • one location is created here: Set VariableSet DB_MapCenter = (Center of (Playable map area))
so it's correct to call RemoveLocation twice here. However, both locations are not needed at same time, so using only one variable for both would suffice, too.

===

The group does not leak, only because it's not destroyed.
It leaks, if you create a new group, meaning you overwrite the the old group, and it's not destroyed, yet.
So, if you call "set udg_TimeLock_LockedUnits = CreateGroup()" multiple times, without destroying it in between, it would leak.
In your case, it seems like it's not needed to ever destroy, or to re-create the group. It looks like you can just keep adding/removing units to it, and it would be fine. No leak, as never a new group overwrites an old one.

Have a look: Memory Leaks
 
Level 12
Joined
May 16, 2020
Messages
660
1st trigger:
  • one location is created here: Set VariableSet DB_CasterPos = (Position of DB_Caster)
  • one location is created here: Set VariableSet DB_MapCenter = (Center of (Playable map area))
so it's correct to call RemoveLocation twice here. However, both locations are not needed at same time, so using only one variable for both would suffice, too.

===

The group does not leak, only because it's not destroyed.
It leaks, if you create a new group, meaning you overwrite the the old group, and it's not destroyed, yet.
So, if you call "set udg_TimeLock_LockedUnits = CreateGroup()" multiple times, without destroying it in between, it would leak.
In your case, it seems like it's not needed to ever destroy, or to re-create the group. It looks like you can just keep adding/removing units to it, and it would be fine. No leak, as never a new group overwrites an old one.

Have a look: Memory Leaks

Thank you! Totally didn't know that you don't have to destroy it... so was useful to ask this questiona fter all :)
 
Status
Not open for further replies.
Top