• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

Leaks

Status
Not open for further replies.
Level 13
Joined
Jan 2, 2016
Messages
978
Okay, so I've seen a lot of people obsessed with removing leaks, so I guess I should clear mine too, but I have few questions about what leaks and what doesn't (and what leaks more than other things). So..
1) Is there any point in doing this:
Set Temp_Point = Position of Triggering unit
Set Temp_Point = Temp_Point with offset 200 towards 180 deg
... do something at Temp_Point ...
or is
Set Temp Point = Position of Triggering unit with offset 200 towards 180 deg
... do something at Temp_Point ...
enough?
2) Does "Triggering Unit" leak or should I do: Set Temp_Unit = Triggering Unit?
3) Do calculations leak? Example:
damage target for (50*(Level of .... for triggering unit))
or shall it be done like:
Set Temp_Integer = (Level of ... for triggering unit)
damage target for (50*Temp_Integer)
or perhaps this is the best way?
Set Temp_Integer = (50*(Level of .... for triggering unit))
damage target for Temp_Integer
4) If I have several "Temp" Variables, that I use in many triggers (often), do I really need to destroy them every time or I can just let them be as they are and just change their values? They shouldn't leak much, right?
5)Is it possible that clearing leaks causes leaks??
When I was still begining to learn how to use triggers, I had a trigger that was working well. Later on I read how to remove leaks and when I started destroying the variables in the end of the trigger - I got lag in the game.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
1. Saw a leak, didn't bother to read the rest
2. No
3. No
4. No need to change if the operations involving it are instantaneous. They don't leak, but if it is a handle, it must be destroyed.
5. No

I think you misinterpreted a function call as a leak.
The reason we do Set Temp_Unit = Triggering Unit
is to have less function calls. Triggering Unit is a function call.
Instead of using Triggering Unit multiple times in the trigger, you will used Temp_Unit instead so you end up using Triggering Unit only once and that is in the Set Temp_Unit = Triggering Unit. The rest of the actions involving Triggering Unit will be on Temp_Unit. But if you only used Triggering Unit once, then there's no point in using Temp_Unit.

The same concept applies to Temp_Integer. Level of Ability of a Unit is a function call.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
Level 13
Joined
Jan 2, 2016
Messages
978
By the way, can you explain the theory why does the 1-st way leak and the 2-nd one doesn't:
1) Set TempLoc = Position of Unit
Set TempLoc = Point centered at TempLoc with offset 200 towards 180 deg.
2) Set TempLoc1 = Position of Unit
SetTempLoc2 = Point centered at TempLoc1 with offset 200 towards 180 deg.

The way I see it - both should be leak free. Just the 1-st one is using 1 variable instead of 2, so why does it leak?
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
Whenever you see a native (BJ's and some custom defined functions as well) returns a location (points in GUI), it's creating a location, which can leak whenever not used properly.
Simplifying this in GUI: Whenever you want to create a unit at a location, move a unit to it, etc. you need a location for that. And when you use (Center of Region/Rect x) or (Position of Unit) etc. you are calling a function to return a location to use it, and when this location is not destroyed without any use, it basically leaks. And there's no way of creating and using and then destroying a location without variables.
An easy way to find function calls in GUI, is to see the Parenthesises. Everything in a Parenthesis is a function call, that returns something (real or integer or locations). So when there's a Parenthesis in Polar Offset Point, that returns a location, it's leaking.

Hope it helps.
 
Level 13
Joined
Jan 2, 2016
Messages
978
Yeah, that helps, but now I have few more questions to clear up everything (that's bothering me) about leaks:

1) Somewhere I read that if I remove (global) location and if I have a local variable, using the same location - the local one will get destroyed too.
I have a trigger doing something like this:
set rand_pt to a random point from playable map area.
set local location l = udg_rand_pt
create special effect at rand_pt
wait 2,4 seconds
(THIS TRIGGER IS RUNING 10 TIMES PER SECOND)
set udg_rand_pt = l

So my question is: if I destroy rand_pt in the end of the trigger - will this affect only the value it is curently set to or will it cause malfunction in my trigger?

2) When do I need to destroy unit groups? Can I just add and remove units from them or does this leak?

3) Do I need to destroy Countdown Timers (if they are gonna be used again in the future) or I can leave them be

EDIT: Nevermind (1), I tested it and it seems to be working properly.
But now I have another question:
I have another trigger that repeats an action in "Mag_Cluster_Point" do I need to remove the point after each loop or do I remove it only once, after the loop has ended?
 
Last edited:
Level 23
Joined
Feb 6, 2014
Messages
2,466
1. Variables that points to the same handle will point to nothing if the handle they points to gets destroyed or removed. Example:
  • Actions
    • Set Loc1 = (Point(1400.00, 400.00))
    • Set Loc2 = Loc1
    • Custom script: call RemoveLocation(udg_Loc1)
    • Cinematic - Ping minimap for (All players) at Loc2 for 1.00 seconds
^That will result to a ping in the center of the map since the Loc2 handle is already removed, but take note that Loc2 is still not equal to null

2. You destroy groups when you don't need it anymore. Example, you want to create a group consisting of all units within range of a certain location, then after doing your actions on the units and you don't need the unit group anymore, you should destroy it.
Unit Groups are automatically created in GUI as Empty Group at Map Initialization. You can add/remove units from it, it won't leak.

3. No, if you're gonna use it again, then don't destroy it. Timers in GUI are like Unit-Groups, they are created at Map Initialization. There's no GUI Actions that creates a timer so if you destroy a timer, you can't use that timer again and you'll have to resort to Custom scripts for a new timer.

I have another trigger that repeats an action in "Mag_Cluster_Point" do I need to remove the point after each loop or do I remove it only once, after the loop has ended?
That depends, where is the "Mag_Cluster_Point" created. If it is created inside the loop, then you should remove it while inside the loop.
 
Level 13
Joined
Jan 2, 2016
Messages
978
Okay, I read both of the topics, but I didn't find anything about removing leaks from "create special effect on unit" (didn't see it being mentioned as leaking either).

And by the way... is "bj_wantDestroyGroup = true" - before creating the unit group, the same as "call DestroyGroup(bj_lastCreatedGroup)" - after creating the group?
 
Level 13
Joined
Jan 2, 2016
Messages
978
Hmm.. I started improving my triggers (again) after reading the leaks posts, but I started wondering... Can "Owner of (Matching Unit)" be replaced with "Matching Player"?

And.. I don't need to clear the leaks from "TempPlayer", right?... Or do I?
(Gosh.. the more information I get - the more questions come to my mind)
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
Remember that Leaks are basically unused contents in the game that use memory (for nothing). For example If you are creating a special effect at a location every 12 seconds you'd better not destroy the location every 12 seconds (and create one), you'd better leave it be As you are using it.

You can have 10000 leaks in a game and don't have a problem (single leak in a trigger that runs every 0.03 seconds after 5 minutes) but gets critical when you have leaks in a looping trigger (gets way worse if it's in a loop). They can get above 100000 if not handled properly.

So some small leaks(strings or waits for example) won't affect the gameplay, but it is recommended not to have them anyway.
 
(Matching player) is no substitute for (Owner of (Matching unit)). That's like saying (Picked player) is the same as (Owner of (Picked unit)).

Memory leaks take a toll quite quickly on my POS laptop. It doesn't take much for me to start lagging. You won't notice these issues on a modern PC due to out-of-order execution and ridiculously fast RAM.
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
(Matching player) is no substitute for (Owner of (Matching unit)). That's like saying (Picked player) is the same as (Owner of (Picked unit)).

Memory leaks take a toll quite quickly on my POS laptop. It doesn't take much for me to start lagging. You won't notice these issues on a modern PC due to out-of-order execution and ridiculously fast RAM.

^That's the reason it is recommended not to have even small leaks.
 
Status
Not open for further replies.
Top