Triggers - Memory Leaks and Custom Scripts

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
> if you have a GUI-map entirely, and you just blatantly convert to custom text, will it improve the lag at all?

Just convert it to JASS?
No.

The GUI IS JASS.

You just can't see the JASS unless you convert it.
 

Tholdalf

New Member
Reaction score
2
Does this work if i have an unit group for heroes that is used all the time?
For example..is the group destroyed when i uses this commands or is it still there and use able?
 

Kazuga

Let the game begin...
Reaction score
110
Great tutorial, but does this mean that you need a variable point/unit group for each time you do the action "Pick every unit in..."? If it does I have lot's of work ahead of me to make my map leakless... Wonder why blizzard didn't think of this making an action "remove picked unit from picked unit group" or something like that...
 
S

ShadowProjec

Guest
Damn... I should have red this a long ago. I guess 90% of the triggers in my map causes leaks, and it will be like a months job to fix it all >_<
 
M

mightyone

Guest
Hello, first may I ask what the definition of a memory leak is? After gathering a few definitions, I still do not know:

Rad:
What is a Memory Leak?
A memory leak is a small bit of information that is not removed after it is used. Converting anything to a non-official variable can cause a memory leak. Point leaks are using center/random points in memory leaks. Group leaks are when you use a unit, player, or destructible GROUP function (Without variables for the group). Region leaks are whenever you convert a 'point with size' or an area, that is not already a variable or preset, to a region.


Originally Posted by SerraAvenger Memory Leak:
A memory leak occurs, when you loose the last pointer to an object that actually uses memory. As you can no longer refer to that object then, you cannot destroy and so you cannot free the memory you allocated by creating it. This memory can no longer be used, so you have small to great perfomance losses.Note that as long you still can refer to the object (due to variables or functions), the memory it occupies will not leak. Still, you should destroy every object as soon as you no longer need it; saving in variables will need even more memory than a simple memory leak. Still you can free the memory and reduce the needed ressources.
You mainly seperate between 2 forms: Normal leaks, and Bad leaks. A bad leak is a leak that happens multiple times (in a loop , in a trigger fireing very often ). Normal leaks are such that only occur once ( In a trigger on map initiallisation creating a point for A unit that shall patrol to that point ).Memory leaks only at the moment you loose the last pointer to the object allocating it, not before and not after. And an object ( location, p.e. ) cannot leak. It is the memory that does, and an object cannot have a leak, it is the code that has.

Originally Posted by emjlr3 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.

AceHart
> Unit - Create 1 footman at (Center of (Region A))
This creates a new point and uses it.
But, once done, the point is lost, hence the leak.

> Set Point = (Center of (Region A))
This will also create a new point.
But, the reference to it will be saved in the variable.
And, upon destruction, this reference, and, therefore, the new point, will be destroyed.
The variable is just fine after that and can be reused for other things.


Also, may I ask if the following examples are memory leaks?

1. unit group, pick every unit in xxx and do:
loop actions:
if picked unit belongs to ally of player 1 = true
// should i make a boolean variable? e.g.
p1allyboolean = ((Picked unit) belongs to an ally of Player 1 (Red))
, and then make the condition p1allyboolean equal to true, then destroy the boolean variable?

2. Unit - Replace (Trained unit) with a Footman using The old unit's relative life and mana. Should i make a unit variable for footman?



Is
Unit - Add a 2.00 second Generic expiration timer to (Last created unit)
the same thing as removing a dying unit from the game?

Can anyone think of any analogies, any real life situations, to make it easier to understand what a memory leak is?
 

vypur85

Hibernate
Reaction score
803
1. You need to set then destroy. No need the boolean or anything. Once you create a unit group (means everytime you newly pick something), you need to destroy it. So, use a variable to pick units then destroy it after using.

2. Nope. It doesn't leak. So far, I think, for GUI, the important ones you should look out are Points, Unit Group, Special Effects and Player Groups (except all player). These are the common ones you will use in your map. Floating text could leak too if not set lifespan (basically it stays visible if you don't destroy it, meaning it leaks).

3. Expiration timer and remove unit are totally different. When timer expires, the unit dies. Unit dies and unit removal are not the same. When unit die, they leave corpse that will decay. This will sort of take memory space and if there are a lot of corpse, it could be somewhat laggy. Removal is total removal. The unit is no longer in existence.

Try posting in the WE help main forum. You might get more response there.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Real life memory leak. I'm sure I've seen one somewhere but can't remember it... :p


Got any little sister? Older (and bigger) brother?
They ever came with "Hey, bro, got some $15? Only until next monday of course"?
Did you ever get it back?


Slightly less real life:
Imagine a hotel (the memory), and lots of little rooms (to put stuff inside like "position of <unit>").
Now, people check in, rooms are busy... everything's just normal.
However, they simply leave without checking out.
At some point, the hotel will appear full even though no one's in.
 

KILLJAW

New Member
Reaction score
0
I think you may have forgotten to mention how to clear a leak from a player.

Ex:
Code:
Update Board FFA
    Events
        Unit - A unit Dies
    Conditions
        ((Dying unit) is A Hero) Equal to True
    Actions
        Set TempPlayer1 = (Owner of (Killing unit))
        Set kills[(Player number of (Owner of (Killing unit)))] = (kills[(Player number of (Owner of (Killing unit)))] + 1)
        For each (Integer A) from 1 to 8, do (If (((Player((Integer A))) slot status) Equal to Is playing) then do (Leaderboard - Change the value for (Player((Integer A))) in theboard to kills[(Integer A)]) else do (Do nothing))
        Leaderboard - Sort theboard by Value in Descending order
        Trigger - Run Victory FFA <gen> (checking conditions)
Code:
Victory FFA
    Events
    Conditions
        kills[(Player number of TempPlayer1)] Equal to 50
    Actions
        Player Group - Pick every player in (All players) and do (If (((Picked player) is an ally of TempPlayer1) Equal to True) then do (Game - Victory (Picked player) (Show dialogs, Skip scores)) else do (Game - Defeat (Picked player) with the message: Defeat!))

How would I clean this leak (if it leaks at all)?
 

aredee

New Member
Reaction score
2
i'm not really get what is memory leak. so, trigger like this is leak, right?

Code:
event
every 15 seconds of game time
condition
action
create 1 grunt for player 12 (brown) at center of region 12 facing default building facing
order (last created unit) to attack-move to center of region 3

and this is the "leakless version" of the above trigger (at least the point)

Code:
event
every 15 seconds of game time
condition
action
set enemyspawnpoint=center of region 12
create 1 grunt for player 12 (brown) at enemyspawnpoint facing default building facing
order (last created unit) to attack-move to center of region 3
custom script call RemoveLocation(udg_enemyspawnpoint)

am i right? and are the fatal errors occurs in-game is caused by high memory leaks?
 

vypur85

Hibernate
Reaction score
803
> "leakless version" of the above trigger

Not exactly but you get the idea, I think. :)

Code:
event
 every 15 seconds of game time
condition
action
 [B]Set Temp_Pt = (Center of Region 3)[/B]
 set enemyspawnpoint=center of region 12
 create 1 grunt for player 12 (brown) at enemyspawnpoint facing default building facing
 order (last created unit) to attack-move to [B]Temp_Pt[/B]
 custom script call RemoveLocation(udg_enemyspawnpoint)
 [B]Custom Script   : call RemoveLocation (udg_Temp_Pt)[/B]

The above trigger is leakless.


> fatal errors occurs in-game is caused by high memory leaks?

I doubt it. It usually means you did something wrong in triggering. Leaks cause lags (you need a lot of leaks to cause noticable lag but don't disregard it if possible). Having leaks in a map is not 'something wrong'. It's just, er, inefficient, I think. Not sure how to describe it.
 

San-D

New Member
Reaction score
15
I have a questions - how do I fix Point Array leaks. Say I have this trigger
Code:
Events
 - Map Init
Conditions
Actions
 For every integer A from 1 to 100 do
 Set Temp_Point[Integer A] = something
How do I clear all 100 point arrays?
 

manofsteel

New Member
Reaction score
36
I have a questions - how do I fix Point Array leaks. Say I have this trigger
Code:
Events
 - Map Init
Conditions
Actions
 For every integer A from 1 to 100 do
 Set Temp_Point[Integer A] = something
How do I clear all 100 point arrays?

Code:
call RemoveLocation(udg_Temp_Point[bj_forLoopAIndex])
Use this inside the loop.

But thats not needed you can just set it remove it, set it remove... it inside the loop.
Code:
Set Temp_Point = something
call RemoveLocation(udg_Temp_Point)
^^both inside loop
 

Manee

New Member
Reaction score
20
i made a footie-type map and it has so much spawn trigger
whenever the main structure of a player gets upgraded to tier 2, every tier 1 units gets replaced by tier 2 units

now, after reading this tutorial, I applied the Custom Script(Unit Group and Points) in every spawn and replacement triggers but my map still gets errors often =/

so I'm wondering... isn't it the role of the custom scripts to prevent such errors?

this is an example of my spawn trigger:

Code:
Event
Time - Every 9.00 seconds of game time
Actions
Player Group - Pick every player in (All players) and do (Actions)
    Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                ((Picked player) Food used) Less than ((Picked player) Food cap)
            Then - Actions
                Set TempPoint = ((Picked player) start location)
                If (((Region centered at TempPoint with size (384.00, 384.00)) contains (Random unit from (Units owned by (Picked player) of type Barracks))) Equal to True) then do (Unit - Create 1 Militia for (Picked player) at TempPoint facing Default building facing degrees) else do (Do nothing)
                Custom script:   call RemoveLocation (udg_TempPoint)
                Custom script:   set bj_wantDestroyGroup = true
                Unit Group - Pick every unit in (Units owned by (Owner of (Last created unit)) of type Arcane Tower) and do (Actions)
                    Loop - Actions
                        Set RallyPoint = (Rally-Point of (Picked unit) as a point)
                        Unit - Order (Last created unit) to Attack-Move To RallyPoint
                        Custom script:   call RemoveLocation(udg_RallyPoint)
            Else - Actions

and this is one example of my replacement trigger

Code:
Events
Unit - A unit Finishes an upgrade
Conditions
(Unit-type of (Triggering unit)) Equal to Barracks II
Actions
Set GroupMilitia = (Units owned by (Owner of (Triggering unit)) of type Militia)
Unit Group - Pick every unit in GroupMilitia and do (Unit - Replace (Picked unit) with a Footman using The old unit's relative life and mana)
Custom script:   call DestroyGroup (udg_GroupMilitia)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top