You're leaking 3 times, once during the
Unit Group creation and twice inside of your
Loop - Actions. Also, you shouldn't be removing
p5 inside of the
Loop - Actions section, you want to Remove it
AFTER you're done picking every unit (so outside and below it). That being said, you did have the right idea with
p5 and you were halfway there.
Here are the most common memory leaks by
type. Note that I will leave some out because I don't think they're worth discussing yet, we can worry about those later. Oh and my use of the word "All" here may be incorrect but again let's not go crazy overthinking it.
[Unit Groups]
All of these functions will leak a Unit Group:
[Player Groups]
All of these functions will leak a Player Group
excluding All Players:
[Points]
If you see the words "
Position of..." or "
Center of..." or "
Point of..." know that you're leaking a Point:
-
Actions
-

Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
-

Item - Create Tome of Experience at (Position of (Last created unit))
-

Special Effect - Create a special effect at (Target point of ability being cast) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
I'm leaking 3 Points in the above trigger ->
(Center of (Playable map area)),
(Position of (Last created unit)), and
(Target point of ability being cast).
[Special Effects]
These are very straight forward and the easiest to deal with. If you create a Special Effect and never Destroy it then you've created a memory leak. You can see that being done in the above trigger. A lot of the time you can simply use the (Destroy last created special effect) Action which will remove the memory leak and clean things up for you automatically. Note that if you intend for a Special Effect to exist forever then it is NOT considered a memory leak so you don't have to Destroy it.
[The Solution]
The solution to these memory leaks is to use Variables to store whatever it is that the function is creating. So what you want to do is Set a
Unit Group,
Player Group, or
Point variable to whatever it is that causes the leak. Then reference that Variable instead of the leaking function. Once you're finished referencing that Variable you would use one of the many Custom Script functions for removing that specific type of memory leak which will get rid of it for good.
Here are some example triggers that use the above solution. These are completely leak free:
-
Actions
-

Set Temp_Unit_Group = (Units in (Playable map area) owned by Player 1 (Red))
-

Unit Group - Pick every unit in Temp_Unit_Group and do (Actions)
-


Loop - Actions
-



Unit - Kill (Picked unit)
-

Custom script: call DestroyGroup( udg_Temp_Unit_Group )
-
Actions
-

Set Temp_Player_Group = (All players controlled by a User player)
-

Player Group - Pick every player in Temp_Player_Group and do (Actions)
-


Loop - Actions
-



Player - Add 100 to (Picked player).Current gold
-

Custom script: call DestroyForce( udg_Temp_Player_Group )
-
Actions
-

Set Temp_Point = (Center of (Playable map area))
-

Unit - Create 1 Footman for Player 1 (Red) at Temp_Point facing Default building facing degrees
-

Custom script: call RemoveLocation( udg_Temp_Point )
-

-------- --------
-

Set Temp_Point = (Position of (Last created unit))
-

Item - Create Tome of Experience at Temp_Point
-

Custom script: call RemoveLocation( udg_Temp_Point )
-
Actions
-

Set Temp_Point = (Center of (Playable map area))
-

Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
-

Special Effect - Destroy (Last created special effect)
-

Custom script: call RemoveLocation( udg_Temp_Point )
Here's some general rules and information about memory leaks:
1) When dealing with memory leaks you will follow this pattern:
Set Variable,
Use Variable (multiple times if you'd like),
Remove Variable.
If you break this pattern then you're doing something wrong and likely creating memory leaks.
2) If you intend for something to exist forever then do not worry about memory leaks. A memory leak only exists when you lose track of something that was meant to be discarded after you were done with it.
3) A nice way to avoid having to deal with memory leaks is to use "constant" variables. These are any Variables that you've Set
once and only once with the intention of reusing them throughout your triggers. For example, you could use a constant Point variable to keep track of where you periodically spawn enemy units - assuming that the position doesn't change. With this design you can avoid having to deal with memory leaks since you already have an existing variable that you can rely on again and again.
For a deeper explanation of what a memory leak is:
C0Memory leaks For a quick lookup on most important actions, read Things That Leak. Introduction Object Leaks Reference Leaks Miscellaneous Conclusion C1Introduction If your computer's memory keeps occupied with stuff you already lost access to, it's called memory leak. It slows down the...
www.hiveworkshop.com