Question about memory leak & variable

Yamuraiha

Member
Reaction score
1
I'm new at memmory leak, since there isn't a way to test if my trigger is a leak or not, I come here to ask professional editor. I did the same as the trigger on the website but I don't know if it is right or not. Someone help me check it.
Trigger:
  • Every 30s
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Set Point_Spawn_Top_Solomon = (Center of Human Top <gen>)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ancient of War 0023 <gen> is alive) Equal to True
          • (Arcane Sanctum 0060 <gen> is alive) Equal to True
        • Then - Actions
          • Unit - Create 4 Footman (Normal) for Player 1 (Red) at Point_Spawn_Top_Solomon facing 30.00 degrees
          • Unit - Create 2 Archer (Normal) for Player 1 (Red) at Point_Spawn_Top_Solomon facing 30.00 degrees
        • Else - Actions
          • Unit - Create 4 Footman (Power) for Player 1 (Red) at Point_Spawn_Top_Solomon facing 30.00 degrees
          • Unit - Create 2 Archer (Power) for Player 1 (Red) at Point_Spawn_Top_Solomon facing 30.00 degrees
      • Custom script: call RemoveLocation (udg_Point_Spawn_Top_Solomon)
      • Unit - Order (Last created unit) to Attack-Move To (Center of Center Top <gen>)

A extra question: Can I used variable "Point_Spawn_Top_Solomon" again in another trigger/action or I do have to create another variable ? Tks for read to this line.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
1) Your trigger leaks at the following line of code:
Trigger:
  • Unit - Order (Last created unit) to Attack-Move To (Center of Center Top <gen>)

The leaking part is:
Code:
(Center of Center Top <gen>)

2) You have to understand what a memory leak actually is. Its not some kind of mystical creature from a fairy tale.
A leak is an "object" you create but never remove. Your computer only has a limited amount of ram. That means you can only create a limited number of "objects". If you dont remove the "objects" after you used them you will eventually run out of ram.
Now, what are those ominous "objects"? For example, each Point is an object.

To explain further, this is what you do with your code:
Trigger:
  • Unit - Order (Last created unit) to Attack-Move To (Center of Center Top &lt;gen&gt;)

Equals
Code:
1) Create a new Point
2) Set that point to the center location of the area "Center Top"
3) Issue the last created unit to attack move to the newly created point
You see where the problem is? The point is never ever removed again. This is a memory leak.

So what you have to do is something like this:
Trigger:
  • set Temp_Point = (Center of Center Top &lt;gen&gt;)
    • Unit - Order (Last created unit) to Attack-Move To Temp_Point
    • call RemoveLocation (udg_Temp_Point)

because now we are able to remove the point again after we used it.


It is very important to differentiate between variables and objects.
Objects actually exist in your memory and take up space. They need to be created and removed.
Variables are just names. Identifiers to talk about objects. You can use the same variable to describe many thousands objects over the span of the game, one at a time. You bind the name to an object, use the variable as a reference to the object, remove the object and then you can bind the name to another object again.

Keep this is mind and memory leaks should not be any trouble for you.
 

vypur85

Hibernate
Reaction score
803
For your extra question, if you still don't quite get what Acc is inferring, it's no - you don't need to create a new variable in another trigger. Just reuse it if situation allows you to do so.
 

Yamuraiha

Member
Reaction score
1
For your extra question, if you still don't quite get what Acc is inferring, it's no - you don't need to create a new variable in another trigger. Just reuse it if situation allows you to do so.
Ah what I want to ask is this:
Trigger:
  • Spawn FootMan
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Set Point_A = (Center of (Playable map area))
      • Unit - Create 1 Footman for Player 1 (Red) at Point_A facing 0.00 degrees
      • Custom script: call RemoveLocation (udg_Point_A)

Trigger:
  • Spawn Knight
    • Events
      • Time - Every 180.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Create 1 Knight for Player 1 (Red) at Point_A facing 0.00 degrees

Is it ok if I set point A in trigger "Spawn FootMan" and use it in Spawn Knight like this, or in the first trigger , I had removed the location and the second trigger won't work? I think it will not work unless I make 2 new trigger, in first one I will set Point_A = (Center of (Playable map area)) every 30 sec of gametime. In the second one which turn on when time elapsed in game is 2s and every 30 sec, the second trigger will remove location (Point_A). is that ok or I will have to create new variable for every unit (because 720= 360*2= 180*4 = 30=24)
 

vypur85

Hibernate
Reaction score
803
> ...I had removed the location and the second trigger won't work?
Yes. It won't work. Since you removed it.

> ...is that ok or I will have to create new variable
You don't really need to 'create new variable' per se. You just need to 'set the variable' again. Both the spawn triggers must have the set variable and removal.

For your reference, just imagine a 'point' as a 'unit'. If you create a unit and then remove it. Do you think you still can use the unit? And, if you create a unit and use it, then you already have no use for it. If you leave the unit there, it takes up memory. That is leak. The difference between 'unit' and 'point' is that you can see the 'unit' visibly but not 'point'. Even though you don't see the 'point', it doesn't mean it's not there and so if you don't remove it, it leaks.

Just remember when you create something, and already have no use of that something, remember to remove it. That's all.
 

Yamuraiha

Member
Reaction score
1
>
> ...is that ok or I will have to create new variable
You don't really need to 'create new variable' per se. You just need to 'set the variable' again. Both the spawn triggers must have the set variable and removal.
But if I set the variable again, it means that every 180 second of game time the variable "Point_A" will be set to 2 different places at the same time. A clearer example:
Trigger:
  • Spawn FootMan
    • Events
    • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
    • Set Point_A = (Center of (Playable map area))
    • Unit - Create 1 Footman for Player 1 (Red) at Point_A facing 0.00 degrees
    • Custom script: call RemoveLocation (udg_Point_A)

Trigger:
  • Spawn Knight
    • Events
    • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
    • Set Point_A = (Center of (Another Region))
    • Unit - Create 1 Knight for Player 1 (Red) at Point_A facing 0.00 degrees
    • Custom script: call RemoveLocation (udg_Point_A)


I set point_A = different places at the same time but then remove them instantly. Will they both work or just one of them ?
 

vypur85

Hibernate
Reaction score
803
It will work fine. There is no such thing as instant simultaneous in this matter. It always follows order. Even if both triggers run at 30 sec gametime, the triggers will still queue one after the other.

Just use my example for your test:
Trigger:
  • Spawn FootMan
    • Events
    • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
    • Unit - Create 1 Footman for Player 1 (Red) at Point_A facing 0.00 degrees
    • Set tempunit = (Last created unit)
    • ....do something...
    • Custom script : call RemoveUnit (udg_tempunit)


Trigger:
  • Spawn Knight
    • Events
    • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
    • Unit - Create 1 Footman for Player 1 (Red) at Point_A facing 0.00 degrees
    • Set tempunit = (Last created unit)
    • ....do something...
    • Custom script : call RemoveUnit (udg_tempunit)

In this case, imagine the 'unit' as 'point'.
Do you think there will be any units left behind? If nothing is left behind = no leak. And it works fine.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
You computer is not a magic machine. Even in the year 2013 it can only do one thing at once.
It will probably run the triggers in that order that they were created in.

If you want to remove leaks you really only need 1 point variable most of the time. The only reason to get 2 variables is if both reference each other or are in any other way dependant on each other.

But there are many other things that leak too, though, points are the most common thing.
 

Yamuraiha

Member
Reaction score
1
tks for all the help and patience, I clearly understand it now. By the way, an extra stupid question: what does "temp" stand for ? Why do people always start their variable with Temp :)
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
It indicates that this variable is of no use other then clearing memory leaks or shortening code.
If a variable starts with "temp" nobody would expect that variable to be used across triggers and the variable can be overwritten without concern.
 
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