Jump to content

Recommended Posts

Posted

~~emjlr3's Memory Leak / Custom Script Guide~~

 

 

I have seen this going around a lot lately, people asking for help with memory leaks and custom scripts. This tutorial is to provide knowledge of the basic memory leaks and ways to clean them up using custom scripts, for those of us who are not yet intone enough with JASS to make all our triggers using such. This also should provide us with a quick answer to all those posts about this, so we can just send people in the direction of this thread, and tell them to read. Let us begin:

 

Let me start by introducing everyone to the not so common terms I will be using:

 

Memory Leak: the leakage of handle objects, or in other words, basically whenever you create something or reference something, other than integers the game loses it’s location, thus causing a leaked piece of memory. Now granted these are cleaned at the end of the game, but if enough pile up during play without being removed, it can cause serious lag to the players, ranging from a little here and there, to complete un-playability, neither of which is wanted.

 

Jass: the scripting language used for scripting Maps and AI files in Blizzard Entertainment's Warcraft III game. Most people make triggers in GUI format, the premade template triggers that are in the World Editor. However, the actual language of these is that of JASS, which can give you almost free reign over every aspect of the game.

 

Custom Script: this is an action in the World Editor Trigger Editor which allows you to type one line of JASS script as opposed to using a template GUI script. This is what we will be using to clean up most of our memory leaks, since Blizzard put in the ability to remove these leaks, but neglected to add them to basic GUI.

 

 

Now many different things can cause memory leaks, these include:

 

Special Effects

Groups

Points

Units

Regions

Forces

Lightning Effects

Floating Text

Countdown Timers

(There may be more which I have forgotten, but these are the ones that need to be dealt with the most, since they are most commonly used.)

 

 

Now I will show you examples of each of the most common, with memory leaks, and then after cleaning them up:

 

Unit Groups

 

Unit Group Bad
    Events
    Conditions
    Actions
        Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
            Loop - Actions
                Unit - Kill (Picked unit)

 

Now this will leak memory for every unit picked, which, depending on how many times this is ran, can add up heavily.

 

Unit Group Good
    Events
    Conditions
    Actions
        Set Temp_Group = (Units in (Playable map area))
        Unit Group - Pick every unit in Temp_Group and do (Actions)
            Loop - Actions
                Unit - Kill (Picked unit)
        Custom script:   call DestroyGroup (udg_Temp_Group)

 

This cleans up all of your leaks. We first set our unit group to a unit group variable, pick all the units in this variable, do our actions, and then destroy the unit group variable, using a Custom Script. Remember that when referencing a variable in JASS, you most use underlines for spaces and put ‘udg’ before the Variable name.

 

Points

 

Point Bad
    Events
    Conditions
    Actions
        Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees

 

 

The unit created at the region leaks. This is not a major leak, but depending on the amount of units created, and how often, it can add up.

 

Point Good
    Events
    Conditions
    Actions
        Set Temp_Point = (Center of (Playable map area))
        Unit - Create 1 Footman for Player 1 (Red) at Temp_Point facing Default building facing degrees
        Custom script:   call RemoveLocation (udg_Temp_Point)

 

 

By setting our position that we want the unit to be created at, creating it at the variable, then removing it, we remove all leaks.

 

Special Effects

 

 

Special Effect Bad
    Events
    Conditions
    Actions
        Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl

 

 

This introduces a new leak, the special effect leak, and has one we just went over, the point leak. We need to remove both of these.

 

 

Special Effect Good 1
    Events
    Conditions
    Actions
        Set Temp_Point = (Center of (Playable map area))
        Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
        Special Effect - Destroy (Last created special effect)
        Custom script:   call RemoveLocation (udg_Temp_Point)

 

 

In the same fashion as before, we remove our leaks. Special effects are one of the only things you can remove through GUI functions, and no custom script is needed. Whenever you create a special effect, you should always destroy it, even if it looks as though it destroys itself, such as in this case with Thunder Clap. Now some special effects, if destroyed directly after being made, never show at all. In that case you have to add a wait in, then destroy the special effect at a later time.

 

 

Special Effect Good 2
    Events
    Conditions
    Actions
        For each (Integer A) from 1 to 10, do (Actions)
            Loop - Actions
                Set Temp_Point = (Center of (Playable map area))
                Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Undead\UnholyAura\UnholyAura.mdl
                Set Temp_SFX[(Integer A)] = (Last created special effect)
                Custom script:   call RemoveLocation (udg_Temp_Point)
        Wait 2.00 seconds
        For each (Integer A) from 1 to 10, do (Actions)
            Loop - Actions
                Special Effect - Destroy Temp_SFX[(Integer A)]

 

This is an example if you wanted to have a wait, and create many special effects at once. This stores each into a special effect variable array, and destroys them all at a later time.

 

Units

 

The last major leak is that of units. Many people like to use dummy units to create neat triggered spells and such. If these units are not removed, they can just pile up all around the map, leading to some major lag. We use our example from before:

 

 

Units Bad
    Events
    Conditions
    Actions
        Unit - Create 1 Dummy Caster for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees

 

 

There is a very easy way to remove them after they are no longer needed. Remember to fix your other point leak too.

 

Units Good
    Events
    Conditions
    Actions
        Set Temp_Point = (Center of (Playable map area))
        Unit - Create 1 Dummy Caster for Player 1 (Red) at Temp_Point facing Default building facing degrees
        Custom script:   call RemoveLocation (udg_Temp_Point)
        Unit - Add a 2.00 second Generic expiration timer to (Last created unit)

 

 

This adds an expiration timer to the unit, so it is destroyed after 2 seconds. This is usually enough time for it to do what it needs to, but you can change it for your personal needs.

 

Other Possibilities

 

That pretty much covers all the major leaks problems people have in their maps. Here are a few more custom script functions you can use to remove other leaks that sometimes occur:

 

 

Custom script: call DestroyForce( udg_Your_Variable ) //Player Group

 

Custom script:   call RemoveRect(udg_Your_Variable) //Region

 

Custom script: call DestroyLightning( udg_Your_Variable ) //Lightning Effect

 

Custom script: call DestroyTextTag( udg_Your_Variable ) //Floating Text

 

 

This is one of the only things that can also be easily destroyed in GUI. There ar two way of doing this, each are equally effective.

 

Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
Floating Text - Destroy (Last created floating text)

 

 

The first simply adds a destroy timer to the text tag, and it will be destroyed in 5 seconds, the second is a manual destroy you can do yourself.

 

Custom script: call DestroyTimer( udg_Your_Variable ) //Countdown Timer

 

and lastly, one good Custom Script to use is that when you have a trigger that will only run once, then is useless. In those cases, put this at the end of the trigger. It can greatly reduce lag in your maps.

 

Custom script:   call DestroyTrigger( GetTriggeringTrigger() )

 

 

Final Trigger

 

Let us put all our newly acquired knowledge together for one final leak less trigger.

 

Final Good Trigger
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Animate Dead
    Actions
        Set Temp_Point = (Position of (Casting unit))
        Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
        Special Effect - Destroy (Last created special effect)
        Set Temp_Group = (Units within 512.00 of Temp_Point matching (((Matching unit) is A structure) Equal to False))
        Custom script:   call RemoveLocation (udg_Temp_Point)
        Unit Group - Pick every unit in Temp_Group and do (Actions)
            Loop - Actions
                Set Temp_Point = (Position of (Picked unit))
                Unit - Create 1 Dummy Caster for (Owner of (Casting unit)) at Temp_Point facing Default building facing degrees
                Unit - Order (Last created unit) to Human Priest - Inner Fire (Picked unit)
                Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
                Custom script:   call RemoveLocation (udg_Temp_Point)
        Custom script:   call DestroyGroup (udg_Temp_Group)

 

You have completed my tutorial. I hope you have learned a thing or two, and happy mapping!!

 

Feel free to visit http://jass.sourceforge.net/index.shtml for a list of all JASS functions known, some JASS tools, and a very good JASS manual.

 

v 1.03

 

---------------------------------------------------------------------------------------------------

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...