Thank you!
Does the dead unit being added to a group cause lag? I'm not too worried about the thing not spawning here and there.
Also I swear I remember reading somewhere that preplaced regions didn't leak. I'm guessing that's only kinda true? is it only for creating units at those places, but not checking if there's any there?
The Unit Group gets destroyed immediately after being used so there's no worry about lag or something like that.
And the solution is simple, just add filters to your Unit Group:
-
Set Variable TempUnitGroup = (Units in X region matching ((Matching unit) is Alive) Equal to True)
Now the Unit Group only contains living units.
Understanding the logic behind what's happening will help make this memory leak stuff click. Understand that all of your triggers in GUI get converted to Jass code, which does a whole lot more behind the scenes, like creating Points and Unit Groups which wind up becoming potential memory leaks. They're potential because you can still manually deal with them by using the Set/Destroy method. Learning a bit of Jass will help make this all clear since you can see exactly what's happening in your functions.
So to clarify what I said before:
In order for the game to know how many units are in a Region it has to go through a whole process:
First a Unit Group is needed to store these units, so one is created:
vJASS:
local group TempUnitGroup = CreateGroup()
So the game creates a brand new Unit Group to store the Units in before any are even found.
Then it proceeds to check for Units inside of the given Region and Adds them to the Unit Group:
vJASS:
call GroupAddUnit(TempUnitGroup, TheUnitFound)
Then it counts the number of Units inside the Unit Group and returns the Integer value to the user.
This value is used in your question -> Is the number of units in my region
Equal to 0?
If this Condition is True then the trigger proceeds to the Actions, otherwise, it either stops the trigger short or proceeds to the Else - Actions (in an If Then Else).
The problem here is that the Unit Group it created at the start of the process never gets destroyed. That is what creates the memory leak.
(Note that this is not the exact process but it gets the point across)
And again:
Units In...
Units matching...
Players matching...
Position Of...
Center Of...
Target Point Of...
Rally-Point As Point
If you see those words outside of a Variable being Set, you're creating a memory leak. There may be some rare exceptions but don't worry about those yet.