Thanks! That did it perfectly.
No problem. I'm not too sure what was wrong with your original method to be honest.
Is that a valid way to avoid leaks?
Unfortunately, that does NOT avoid the
memory leak.
About leaks, I confess I don't understand them entirely.
First off: A memory leak is just some information (data) that your computer is keeping track of even though it's no longer needed. It's sort of like a file you've forgotten to delete.
So this Action here is what's creating the Unit Group memory leak:
-
Set unitgroup = (Units in (Playable map area) owned by Player 4 (Purple))
This Action runs code that does the following:
1) It creates a brand new Unit Group
object. Think of it like if you created a brand new Unit. Your
unitgroup variable then
tracks that
object.
2) It fills this Unit Group
object with the Units that match your filter -> (Units owned by Player 4).
3) You can then use the
Pick Every Unit action to interact with the units inside of this specific Unit Group
object. You can do this at anytime as long as you're tracking the
object in a Unit Group variable (like
unitgroup).
With that in mind, understand that this memory leak only occurs when you lose
track of the Unit Group
object without Destroying it first.
Here is the main way to successfully Destroy a Unit Group object and fix the memory leak (I used an alternative method in my first post):
-
Actions
-

Set unitgroup = (Units in (Playable map area) owned by Player 4 (Purple))
-

Custom script: call DestroyGroup( udg_unitgroup )
When you run that Custom Script you're not destroying the
unitgroup variable, you're destroying the Unit Group
OBJECT that was being
TRACKED by that variable. Hopefully that makes sense.
Here's an example of losing
track of a Unit Group
object:
-
Actions
-

Set unitgroup = (Units in (Playable map area) owned by Player 4 (Purple))
-

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

Custom script: call DestroyGroup( udg_unitgroup )
We've created two Unit Group
objects in this trigger, since each time you use "Set unitgroup" it creates a brand new object. The issue here is that we've lost
track of the first
object since our
unitgroup variable has been assigned to track the second Unit Group
object. This means that we can NEVER get rid of the first Unit Group
object since our Custom Script is only able to reference and destroy the second Unit Group
object. So we've made a mistake and accidentally created 1 memory leak here. To fix this you would need to introduce another Custom Script after the first "Set unitgroup".
Now keep in mind that practically every map has memory leaks and most of the time they aren't going to cause noticeable damage since they take up such a small amount of space. But if you're not careful with your triggers then you may end up creating A LOT of leaks, for example maybe you have a Timer that runs every 0.01 second which then runs a Trigger that unintentionally creates 10 Memory Leaks. That's 10 * 100 = 1000 Memory Leaks per second! It could really add up over time. It'd be like if you created 1000 almost-empty text files on your computer every second, they may take up a VERY SMALL amount of space but eventually they will start to eat up your computer's storage.
That's why you should try to delete (Destroy/Remove) them. Or as we say, "clean up" your memory leaks.
Also, here are the main kinds of memory leaks you'll deal with most of the time:
Points, Unit Groups, Player Groups, Special Effects.
If you take care of these your map should be fine. (It'll probably be fine regardless)