A leak is when you lose reference to something, therefore you can never remove/destroy it. It will exist in the game's memory forever.
-
Set Variable TempPoint = Center of RegionA
-
Set Variable TempPoint = Center of RegionB
The above trigger leaks a single Point, which is the Point created from the first TempPoint variable (Center of RegionA).
The second usage of TempPoint (Center of RegionB) is not considered a leak yet because we still have a reference to it --> TempPoint.
This means that the second Point can still be removed using:
-
Custom script: call RemoveLocation (udg_TempPoint)
Understand that TempPoint is NOT the Point itself but instead a reference to a Point. (Note: Points are also known as Locations in non-GUI syntax).
Things that don't leak:
Integer, Real, Boolean, String
I've read that Units (and maybe the other types I listed) do technically leak but it's pointless to worry about them.
Long story short, when working in GUI you should really only be focusing on removing these types of leaks:
Unit Groups, Player Groups, Points, Special Effects
Which are cleaned up like so:
-
Custom script: call DestroyGroup(udg_UnitGroupName)
-
Custom script: call DestroyForce(udg_PlayerGroupName)
-
Custom script: call RemoveLocation(udg_PointName)
-
Special Effect - Destroy last created effect
The words Destroy and Remove are basically used interchangeably when it comes to cleaning up leaks.
So with that in mind, your trigger is actually the optimal thing to do because it's REMOVING the Unit, which means that the Unit is being freed from the game's memory. But like I said earlier, you don't need to worry about cleaning up Unit leaks. Units upon dying will Decay and be removed by the game automatically (unless of course you prevent them from decaying). All you've done here is clean up the Unit immediately instead of letting it get cleaned up by... natural causes (if it would be killed)
Another case for cleaning up leaks has to do with the use of Local variables. You need to set Local variables to null when you're done using them (integer, real, boolean, and string are excluded from this). Contrary to before, you DO need to null Unit variables and other non-excluded variable types. This is only something to worry about if you're coding in Jass or using local variables with Custom script in your GUI triggers.