• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

About Trigger Leaks...

Status
Not open for further replies.
When you create an object (a unit, a location, a group ...), its datas are stored in the RAM and use some space. These objects are said to leak when you don't need them anymore but they are still occupying memory. For a unit, it's pretty rare since you see them while they are not removed, but for locations, people often create a bunch of them, use them once and don't care of them anymore.
Besides, you can always refer to a unit even if it is not stored into a variable. But it's not the case for everything.

Actually 1 leak is meaningless and there are few types for which it can become a problem. For example, you never create a new player.
  • Set Player = (Get triggering player)
  • Set Player = (Get triggering player)
It won't leak because the player is the same for both instances.
But every function that returns a location create one of them by doing so.
  • Set Location = (Point of ability being cast)
  • Set Location = (Point of ability being cast)
This leak because even if the 2 locations have the same properties, they are not the same object (in jass, using the condition GetSpellTargetLoc() == GetSpellTargetLoc() is a good way to see that it creates 2 different objects). As they are created, they need to be destroyed somewhere, which is impossible if they are not in a variable.
So
  • Unit - Create a footman at (Location (0,0)) ....
This will always leak if you use a function instead of a variable.



There are 2 ways to avoid leak.

- You destroy the objects you created with a custom script. Most type has a function for that, such as "RemoveLocation" or "DestroyGroup". There are also specific ways : you can put
  • Custom script: set bj_wantDestroyGroup = true
before a "For Group" or a "Get random unit in group". The group will be automatically destroyed after its use in that case.

-You don't create the object by using a trick. In jass, for example, you can use reals instead of locations, which is leakless. You can also create a global object and change its property (it's called recycling). For example, there is a function "MoveLocation" (don't think if it's available in GUI, though) that just change the position of an existing location so you don't have to destroy it every time. The same goes for groups that you can empty if your only method for filling them is to use the action "Group - Add unit" (because "Units in region" and the others always create a new group). It's mainly a jass/vjass method, I don't know if it can be properly done in GUI.


You should take a look at this for types that cause leak in GUI.

I hope I was clear enough. There are more to know about leaks (string leak / local variable leak / text tags leakless...) but it's already a large piece.
 
Status
Not open for further replies.
Top