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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top