Getting Rid Of Memory Leak -In GUI

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

User avatar
qweasd011
Forum Addict
Posts: 451
Joined: November 21st, 2008, 9:36 am
Title: Coleen!

Getting Rid Of Memory Leak -In GUI

Post by qweasd011 »

What Are Memory Leaks

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 :P.

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 )
So you can basicly see that I moved the "(Center of UnitSpawn)" action, to a "Set Variable" action. Then after using it, you destroy it. Note, that in UMSWE, it would look like 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 (270.0) degrees
Point - Remove TempPoint
This works the same for Unit Groups and Player Groups. Except you change the last line too (if you're using the Custom Script action):

Code: Select all

Custom script: call DestroyGroup( udg_TempGroup )
and

Code: Select all

Custom script: call DestroyForce( udg_TempForce ) //Force = Player Group
UMSWE and WEU have both of these actions.

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
You can also just use that action on "Last Created Special Effect" if there is no wait involved (but I guess that's rare).

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())"
or

Code: Select all

Trigger - Destroy (Triggering Trigger)
if you're using UMSWE/WeU


Anyhow, that's it.
Image
User avatar
Kai
Junior Member
Posts: 33
Joined: January 18th, 2009, 2:29 pm
Title: Kookibuzation
Location: Kooki Corporation

Re: Getting Rid Of Memory Leak -In GUI

Post by Kai »

Add the link to leak checker ;p
Image
User avatar
Risen
Forum Staff
Posts: 811
Joined: January 1st, 2008, 12:58 am

Re: Getting Rid Of Memory Leak -In GUI

Post by Risen »

qweasd011, I think it would be a good idea to add all of your tutorials in one post, under a labelled spoiler, More cleaner that way.
Also, I think this might be useful to add..
Spoiler:

Code: Select all

boolexpr
    call DestroyBoolExpr(someBoolExpr)
conditionfunc
    call DestroyCondition(someConditionFunc)
defeatcondition
    call DestroyDefeatCondition(someDefeatCondition)
effect
    call DestroyEffect(someEffect)
filterfunc
    call DestroyFilter(someFilterFunc)
fogmodifier
    call DestroyFogModifier(someFogModifier)
force
    call DestroyForce(someForce)
group
    call DestroyGroup(someGroup)
image
    call DestroyImage(someImage)
itempool
    call DestroyItemPool(someItemPool)
leaderboard
    call DestroyLeaderboard(someLeaderboard)
lightning
    call DestroyLightning(someLightning)
multiboard
    call DestroyMultiboard(someMultiboard)
quest
    call DestroyQuest(someQuest)
texttag
    call DestroyTextTag(someTextTag)
timer
    call DestroyTimer(someTimer)
timerdialog
    call DestroyTimerDialog(someTimerDialog)
trigger
    call DestroyTrigger(someTrigger)
ubersplat
    call DestroyUbersplat(someUbersplat)
unitpool
    call DestroyUnitPool(someUnitPool)
gamecache
    call FlushGameCache(someGameCache)
unit
    call RemoveUnit(someUnit)
item
    call RemoveItem(someItem)
location
    call RemoveLocation(someLocation)
rect
    call RemoveRect(someRect)
region
    call RemoveRegion(someRegion)
weathereffect
    call RemoveWeatherEffect(someWeatherEffect)
Image
Wanna learn to hack maps? --> Guide
User avatar
qweasd011
Forum Addict
Posts: 451
Joined: November 21st, 2008, 9:36 am
Title: Coleen!

Re: Getting Rid Of Memory Leak -In GUI

Post by qweasd011 »

yeah edit my post?
Image