• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

What is RemoveLocation ?

Status
Not open for further replies.
This function is used to free up memory from stoing unneed data about location.
  • Custom script: call RemoveLocation (udg_yourLocation)
Whenever you are refering to any position War3 engine has to calculate it for further purposes, and thus it takes memory. Since most of actions are dynamic, given point can quickly be useless and if not destroyed will be just a ballast for memory. Thats why we try to remove such leaks.
At first we have to set given location to a variable - it will point given location.

Egzample:
  • Init
    • Events
      • Unit - Starts the effect of ability
    • Conditions
      • <some conditions>
    • Actions
      • Set temp_u = (Triggering unit)
      • Set temp_point = (Position of temp_u)
      • Special Effect - Create a special effect at temp_point using <model path>
      • Special Effect - Destroy (last created special effect)
We have set two variables here. Since we are not talking about unit, I'll leave that. However, as you can see variable has been set to point on given point, but after we use that location (just for creating effect) its useless since our caster can change position/die/tons of other stuff. Reference to that location is quickly lost, (when for eg you recast that spell, variable will now point at another point) but data (coordinates of location etc..) will be still stored in memory, creating a 'leak'. High amount of leaks can make game unplayable, thus all leaks should be removed if able.

Usefull link: click here.
 
Level 20
Joined
Oct 21, 2006
Messages
3,230
RemoveLocation() removes the location that is defined in the ().

Whenever you use a location in your trigger like this:
  • Leaking Trigger
    • Events
    • Conditions
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
It automatically creates a new location to the center of the playable map area. This causes a memory leak. Memory leaks may slow down the map if there are enough many of them.

To fix the trigger and get rid of the memory leak you need to use the RemoveLocation() function.
  • Leakless Trigger
    • Events
    • Conditions
    • Actions
      • Set Point1 = (Center of (Playable map area))
      • Unit - Create 1 Footman for Player 1 (Red) at Point1 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_Point1)
We are storing the point to a point type variable first so that we can use it in the RemoveLocation() function.

For more about memory leaks read this thread. It is a sticky so you should have read it on the first place before coming up with this thread.

EDIT
Spinnaker already made a similiar post before me because I used too much time refining my post but hopefully you find this post useful.
 
Level 13
Joined
Jun 22, 2004
Messages
783
Perhaps I can enlighten a couple of things.
Whenever you use a point function, you don't actually leak memory. You create an object in your memory that you are not going to use afterwards, and basically lose track of because you didn’t save the reference label(integer number) referring to the object in memory anywhere.
Thus we speak of a missing object in your memory that is not serving any purpose.

Now back to the explanation.

What the function does is, it destroys a location object that is created in your memory.
You could somewhat compare it with Unit - Remove Unit.

Now you might wonder, ok why do I have to remove an object? I don't go around removing units right!?
Well, no cause most of the time you are using your units, and they are sitting there on your map anyway, so you’ll notice.
Point (objects) are slightly different. You can’t see them on your map, but they do get made automatically by the editor. Whenever you call a point function it basically returns you an instance of that object.

Now there is not something particularly bad with this. The catch however is that it will create 2 separate point objects in your memory when you have 2 identical actions that retrieve the same location through the same function.

  • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
  • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
So you create 2 unit objects (which is what you asked), but the editor also creates two location objects. The fact that two location objects are made is not that bad (they don’t suck up as much memory as other objects) But ask yourselves, what are you going to do with those location objects after you placed the units? Exactly! Nothing... :(.

So the bigger concern is that you are only going to use them once, and probably never again touch them (even though it might feel like that when you call upon that same function again).

This is why you save the return values of those point functions like people in above posts mention so you save the reference to the object and once you have used the object to place whatever you wanted to place. You can safely remove the location so it doesn’t smurf/troll/wander around in your memory and stack up with other locations objects you make throughout your map and not get removed on their turn either.
 
Status
Not open for further replies.
Top