• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Leak or no leak?

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
Hi

I've got a spell that counts units that it damages so it doesn't damage them more than once. (They get added to a group that is arrayed) However my question is that when the spell finishes a loop by max distance being reached everything gets overwritten, so do I need to clear the Group of the original one? If so how do I remove a leak of a group that is arrayed?
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
  • Custom script: call DestroyGroup(udg_Group[array_index])
  • Custom script: set udg_Group[array_index]=null
 
Level 26
Joined
Sep 26, 2009
Messages
2,424
It actually depends on how you are using the unit group.

a) If you add/remove units into already existing unit group using one of the following:
  • Unit Group - Add *unit* to *unit group*
  • Unit Group - Remove *unit* from *unit group*
Then you don't need to destroy the unit group, as you are reusing it (those two actions above do not create new unit group and because of that they cannot cause leak).
Actually, if you destroy the unit group via custom script and then to try to add/remove units into it, it will bug your system as the game doesn't have where to add those units (since you destroyed the unit group).

b) If you add/remove units into unit group by declaring unit group, aka something like this:
  • Set *unit group* = (Units in *somewhere*)
  • ... or ...
  • Unit Group - Pick every unit in (Units in *somewhere*) and do (Actions)
    • Loop - Actions
then you need to do what chobibo wrote, as you create new unit group and in case of you put it into variable, you overwrite the previous unit group there (if there is any) and so you cause memory leak.
 
Level 13
Joined
Oct 16, 2010
Messages
731
Here's what I do

  • Final Shot Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer FS_LoopInt) from 1 to FS_MaxLoop, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • FS_Distance[FS_LoopInt] Greater than 30.00
            • Then - Actions
              • Set Spell_CasterPoint = (Position of FS_Dummy[FS_LoopInt])
              • Set Spell_TargetPoint = (Spell_CasterPoint offset by 30.00 towards FS_Angle[FS_LoopInt] degrees)
              • Unit - Move FS_Dummy[FS_LoopInt] instantly to Spell_TargetPoint, facing FS_Angle[FS_LoopInt] degrees
              • Set FS_Distance[FS_LoopInt] = (FS_Distance[FS_LoopInt] - 30.00)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Terrain pathing at Spell_TargetPoint of type Walkability is off) Equal to True
                • Then - Actions
                  • Unit - Kill FS_Dummy[FS_LoopInt]
                  • Set FS_Angle[FS_LoopInt] = FS_Angle[FS_MaxLoop]
                  • Set FS_CasterUnit[FS_LoopInt] = FS_CasterUnit[FS_MaxLoop]
                  • Set FS_Distance[FS_LoopInt] = FS_Distance[FS_MaxLoop]
                  • Set FS_Dmg[FS_LoopInt] = FS_Dmg[FS_MaxLoop]
                  • Set FS_Dummy[FS_LoopInt] = FS_Dummy[FS_MaxLoop]
                  • Set FS_Group[FS_LoopInt] = FS_Group[FS_MaxLoop]
                  • Set FS_LoopInt = (FS_LoopInt - 1)
                  • Set FS_MaxLoop = (FS_MaxLoop - 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • FS_MaxLoop Equal to 0
                    • Then - Actions
                      • Trigger - Turn off (This trigger)
                    • Else - Actions
                • Else - Actions
                  • Set Spell_UnitGroup = (Units within 100.00 of Spell_TargetPoint matching ((((Matching unit) is A ground unit) Equal to True) and ((((Matching unit) is alive) Equal to True) and (((Owner of (Matching unit)) is an enemy of (Owner of FS_CasterUnit[FS_LoopInt])) Equal to True))))
                  • Unit Group - Pick every unit in Spell_UnitGroup and do (Actions)
                    • Loop - Actions
                      • Set Spell_TargetUnit = (Picked unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Spell_TargetUnit is in FS_Group[FS_LoopInt]) Equal to False
                        • Then - Actions
                          • Unit - Cause FS_CasterUnit[FS_LoopInt] to damage Spell_TargetUnit, dealing FS_Dmg[FS_LoopInt] damage of attack type Spells and damage type Universal
                          • Set FS_Dmg[FS_LoopInt] = (FS_Dmg[FS_LoopInt] x 0.90)
                          • Special Effect - Create a special effect attached to the origin of Spell_TargetUnit using Abilities\Weapons\GlaiveMissile\GlaiveMissileTarget.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • Unit Group - Add Spell_TargetUnit to FS_Group[FS_LoopInt]
                        • Else - Actions
                  • Custom script: call DestroyGroup(udg_Spell_UnitGroup)
              • Custom script: call RemoveLocation(udg_Spell_CasterPoint)
              • Custom script: call RemoveLocation(udg_Spell_TargetPoint)
            • Else - Actions
              • Unit - Kill FS_Dummy[FS_LoopInt]
              • Set FS_Angle[FS_LoopInt] = FS_Angle[FS_MaxLoop]
              • Set FS_CasterUnit[FS_LoopInt] = FS_CasterUnit[FS_MaxLoop]
              • Set FS_Distance[FS_LoopInt] = FS_Distance[FS_MaxLoop]
              • Set FS_Dmg[FS_LoopInt] = FS_Dmg[FS_MaxLoop]
              • Set FS_Dummy[FS_LoopInt] = FS_Dummy[FS_MaxLoop]
              • Set FS_Group[FS_LoopInt] = FS_Group[FS_MaxLoop]
              • Set FS_LoopInt = (FS_LoopInt - 1)
              • Set FS_MaxLoop = (FS_MaxLoop - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • FS_MaxLoop Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
In the casting trigger I pick all the units of the MaxIndex and remove them individually. The only point in which I use "Set variable" for the groups is when overwriting. I'm guessing that I'll need the custom script?
 
Level 12
Joined
May 20, 2009
Messages
822
It actually depends on how you are using the unit group.

a) If you add/remove units into already existing unit group using one of the following:
  • Unit Group - Add *unit* to *unit group*
  • Unit Group - Remove *unit* from *unit group*
Then you don't need to destroy the unit group, as you are reusing it (those two actions above do not create new unit group and because of that they cannot cause leak).
Actually, if you destroy the unit group via custom script and then to try to add/remove units into it, it will bug your system as the game doesn't have where to add those units (since you destroyed the unit group).

b) If you add/remove units into unit group by declaring unit group, aka something like this:
  • Set *unit group* = (Units in *somewhere*)
  • ... or ...
  • Unit Group - Pick every unit in (Units in *somewhere*) and do (Actions)
    • Loop - Actions
then you need to do what chobibo wrote, as you create new unit group and in case of you put it into variable, you overwrite the previous unit group there (if there is any) and so you cause memory leak.

In the second case of B,
  • Custom script: set bj_wantDestroyGroup = true
Is perfectly fine.
 
Status
Not open for further replies.
Top