Official Forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Official Forums


 
HomeLatest imagesRegisterLog in

 

 Memory Leaks

Go down 
2 posters
AuthorMessage
Elmo
Site Master
Site Master



Number of posts : 65
Registration date : 2008-07-24

Memory Leaks Empty
PostSubject: Memory Leaks   Memory Leaks Icon_minitimeSun Jul 27, 2008 1:35 am

You mastered World Editor, you're king of the crop! You test your map on BNet... and... Oh shit! Big black screen of death afterwards! What went wrong?! D:

Well, my map making friend, you have experienced memory leaks! Don't fret -- they're fixable!

First, let's define a memory leak.
Technical definition: An unnamed variable of data is created and stored on the RAM. Because the variable is unnamed, it cannot be "contacted" by triggers to be removed. Therefore, this unnamed variable remains in the RAM until the end of a game, where all the data created by the game is removed (at the black screen of doom).
Layman's terms: Data is created that cannot be deleted until the end of the game, and builds up; thus causing lag.

Now that you know what a leak is, it's time to remove them. There are several types of leaks, both in GUI and JASS. I will explain each type as extensively as possible, along with the way to fix them.

Note: Only actions leak in a trigger. Events and conditions do not.

Location Leak:
Location leaks are extremely common. This is because using coordinates (x and y values for locations) in GUI is difficult. A location is a piece of data that stores two numbers, an x and a y. Locations occur in several triggers, common examples are:
  • Position of unit (the unit's coordinates are stored in the variable, x and y)
  • Centre of region (coordinates for the middle of the region)
  • Random point in region (a random set of coordinates that are within the region)
  • Point of ability being cast (the coordinates of where the ability was cast to)

Location leaks are best caught with your common sense. If you see an action that involves the location, position, point, etc, of anything then it is vital you take the following steps to remove them.

Removing A Location Leak:
  1. Create a point-type variable (see: Variable Editor) with an array. It will be referenced to as temppoint from hereon in.
  2. Look at your leaky action, and find the part that leaks (ie: the part that looks like (Position of (Picked Unit)))
  3. Right before the action with the leak, add the action General - Set Variable
  4. Set temppoint[#] to the leaky action using any array number (ie: (Position of (Picked Unit)))
  5. Replace the leaky command with your variable (ie: instead of (Position of (Picked Unit)), it will now look like temppoint[#])
  6. After the leaky command make the action General - Custom Script
  7. For the custom script, set it to read
    Code:
    call RemoveLocation(udg_temppoint[#])
    //Note: don't actually use "#" in the square brackets. Use the array number you used in step 4.



Group Leak:
A group leak is when any type of group is created. This includes both player and unit groups. Common examples of group leaks include:
  • Pick every player ... (It creates a group and adds all the players that match your condition, the group that is created is the leak)
  • Pick every unit ... (Same as pick every player, but a unit group instead of a player group is created)


Removing A Group Leak:
  1. Create a unit/player group variable (see: Variable Editor) with an array. It will be referenced to as tempgroup from hereon in.
  2. Look at your leaky action, and find the part that leaks (ie: the part that looks like Pick every unit in (Playable map area))
  3. Right before the action with the leak, add the action General - Set Variable
  4. Set tempgroup[#] to the leaky action using any array number (ie: Units in(Playable map area))
  5. Replace the leaky command with your variable (ie: instead of Pick every unit in (Playable map area), it will now look like Pick every unit in tempgroup[#])
  6. After the leaky command make the action General - Custom Script
  7. If it was a unit group, for the custom script, set it to read
    Code:
    call DestroyGroup(udg_tempgroup[#])
    //Note: don't actually use "#" in the square brackets. Use the array number you used in step 4.
  8. If it was a player group, for the custom script, set it to read
    Code:
    call DestroyForce(udg_tempgroup[#])
    //Note: don't actually use "#" in the square brackets. Use the array number you used in step 4.



Special Effect Leak:
A special effect leak just means that a special effect still exists. Just because you can't see it, doesn't mean it's not there. This means that any time you use the action Special Effect - Create effect at point without using the action Special Effect - Remove special effect, there's a leak.

Removing A Special Effect Leak:
You have two options. If you're only creating one effect, whose death effect is the effect you want to see (usually the death animation of effects is the one you want) then use these steps. Otherwise, scroll down a bit.
  1. After the create special effect command, create an action using Special Effect - Destroy special effect
  2. Set the special effect to be removed as Last Created Special Effect

If you have multiple effects, or effects with death animations you don't want, you will need to use variables.
  1. Create a special effect variable (see: Variable Editor) with an array. It will be referenced to as tempeffect from hereon in.
  2. After the create special effect command, create a new action using General - Set Variable
  3. Set tempeffect[#] to Last Created Special Effect
  4. Now, you can add in waits, so that the players can see the animation you like.
  5. After the wait, add the action Special Effect - Destroy special effect
  6. This time, instead of destroying Last Created Special Effect, you destroy tempeffect[#].



Unit Leaks:
The only time to be concerned with unit leaks is if you're using dummy units. This is because you do not see dummy units, and therefore are useless after they've been created and used.

Removing A Unit Leak:
  1. After the create unit action, add the action Unit - Set Timed Life
  2. For the time, any amount of time will do as long as you give enough time for the dummy to do whatever it needs to do.
  3. For the type, they're all generally the same. Most commonly used is the generic expiration timer.
  4. For the unit, choose Last Created Unit




JASS leaks: This part can wait Razz
Back to top Go down
http://www.clantdom.darkbb.com
Elmo
Site Master
Site Master



Number of posts : 65
Registration date : 2008-07-24

Memory Leaks Empty
PostSubject: Re: Memory Leaks   Memory Leaks Icon_minitimeSun Jul 27, 2008 1:36 am

I'm not about to go and approve my own tutorial... So er, any Shamans or Demo wanna approve it for me?
Back to top Go down
http://www.clantdom.darkbb.com
TDoM-M_Odin
Grunt
Grunt
TDoM-M_Odin


Number of posts : 137
Age : 30
Registration date : 2008-07-26

Memory Leaks Empty
PostSubject: Re: Memory Leaks   Memory Leaks Icon_minitimeSun Jul 27, 2008 4:12 pm

Hey, Elmo, Great tutorial. I went ahead and linked to it from mine in the disclaimer.
Back to top Go down
Elmo
Site Master
Site Master



Number of posts : 65
Registration date : 2008-07-24

Memory Leaks Empty
PostSubject: Re: Memory Leaks   Memory Leaks Icon_minitimeSun Jul 27, 2008 6:40 pm

Thanks Very Happy
My next step will be a tutorial explaining variables and the variable editor, you can link to mine in yours too or just leave it with your instructions.
Back to top Go down
http://www.clantdom.darkbb.com
TDoM-M_Odin
Grunt
Grunt
TDoM-M_Odin


Number of posts : 137
Age : 30
Registration date : 2008-07-26

Memory Leaks Empty
PostSubject: Re: Memory Leaks   Memory Leaks Icon_minitimeSun Jul 27, 2008 7:58 pm

Once you do that, I will edit mine again and put the link in it.
I'll say something like "If you wanted a deeper explanation on variables, or you are still confused go here --> (Elmo's variable guide) <--"
Or something of the sorts.
Back to top Go down
Sponsored content





Memory Leaks Empty
PostSubject: Re: Memory Leaks   Memory Leaks Icon_minitime

Back to top Go down
 
Memory Leaks
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Official Forums :: Community :: Tutorials :: Submissions-
Jump to: