Memory Leaks are leakage of handle objects...that is...all objects excluding: Integers (including: Unit-Types, Item-Type and AbilityID), Reals, Booleans and Strings. That is: When you create a object, and you lose the reference of it, so it falls out of reach, and is thus a leaked piece of memory that won't be cleaned until the map finishes (thus, adds to exiting times).
Which Leaks Should I Be Concerned With?
Only the leakage of objects you dynamically create...that is...objects that get temporarely created in-game. So no need to worry about pre-placed units, regions, triggers and players (all these are still handle objects).
In the end, you mostly need to worry about two object-types...these are: Locations and Unit Groups.
Where/When Does It Leak.
The thing is... EVERY time...in the Trigger Editor...when you are making an action...and you open up one of those GUI window labeled "Point"...and select something in it "except" a variable... a point will be created for you, but will "leak" becouse you don't catch it and dispose of it when you're done.
Same lies with Unit Groups, all the actions in that GUI window, except the "Last Created Unit Group" one, will leak the unit-group they create.
These are the 2 most serious things, as they are the type you use the most (think about every time you use the actions: Center Of Rect, Position Of Unit, Pick All Units In ... And Do Action - All these are leaking unless you catch the created objects and dispose of them properly). Player Groups are also created a few times, but not as often. However, they can be handled using the same way as mentioned further down.
Then there are also the "temporary" Units and Special Effects one creates.
And to a even lesser extent, one sometime creates:
Regions, Timers, Timer Dialog Windows, Temporary Dialog Windows, Temporary Multiboards, Temporary LeaderBoards, Floating Texts, Sounds and Visibility Moderators.
But these are most of the time way too rare to care about. And there is a certain rule of thumb, if the trigger runs only once (or just rarely), you don't need to worry about it.. But if it's a common trigger, like a periodic event, or something big....or if it's a trigger where you're Looping alot, then you should go through it and cover up all memory leaks in it.
So How Do I Then Clean Up Memory Leaks?
Blizzard gave us a bunch of functions to destroy these created objects...but unfortunately, they didn't add them to the GUI

So basicly, you have 2 options... You can either;
* Use Custom Script actions to use the Blizzard natives in JASS, or...
* Get WEU or UMSWE...as they have these actions included in GUI
This tutorial explains both.
What you do is.
First: you create 1-2 Point variables named something like: TempPoint, and a Unit Group variable named similarely...
Then, whenever you see yourself selecting something from a Point window or a Unit Group window except in a "Set Variable" action... you have to instead do the following:
Code: Select all
Set TempPoint = (Center of UnitSpawn <gen>)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing degrees
Custom script: call RemoveLocation( udg_TempPoint )
Code: Select all
Set TempPoint = (Center of UnitSpawn <gen>)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing (270.0) degrees
Point - Remove TempPoint
Code: Select all
Custom script: call DestroyGroup( udg_TempGroup )
Code: Select all
Custom script: call DestroyForce( udg_TempForce ) //Force = Player Group
Now, it's generally the same thing what you do with "Temporary Units" and Special Effect. But luckily, WE has a action for destroying these.
Depending on wether there is a Wait action between the point where you create your special effect, and where you want to destroy it...you can set "Last Created Special Effect" in a special effect variable, then just use:
Code: Select all
Special Effect - Destroy TempSFX
Note, that...since two triggers could be using the same SFX variable at the same time...you should try to either have a controlled access to these variables....or better...derive Local variables for you to use. But that's something I won't cover in this tutorial.
But yeah, Removing Units work the same way. To be safe, you might wanna first Kill the unit, then Remove it, as there have been problems with Removing units directly in certain situations (if it's hidden f.ex.). (Oh, and all rumors about "Removing Units" leaking tons of memory are wrong. There isn't even much sense in that anyways, so Removing Unit is a secure thing to do (as I say, just to be safe, kill the unit first)).
And for all the other types I mentioned above...in most of the cases there is a GUI action for destroying it.
One Last Tip
In triggers that run only once (Initialization Triggers and Cinematic Triggers), you can add to the end of it the following action to destroy it, people have reported that it's quite effective.
Code: Select all
Custom Script: "call DestroyTrigger(GetTriggeringTrigger())"
Code: Select all
Trigger - Destroy (Triggering Trigger)
Anyhow, that's it.