Does this leak?

Smitty

Member
Reaction score
20
Here's a trigger I'm using as part of a spell, but I'm not sure if the variables TempAngle and TempAngle2 are leaking.
Trigger:
  • MoI Active
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Master of Illusion
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Target unit of ability being cast) is in IllusionistIllusions) Equal to True
        • Then - Actions
          • Set TempPoint = (Position of (Target unit of ability being cast))
          • Set TempPoint2 = (Position of (Casting unit))
          • Set TempAngle = (Facing of (Triggering unit))
          • Set TempAngle2 = (Facing of (Target unit of ability being cast))
          • Unit - Move (Target unit of ability being cast) instantly to TempPoint2, facing TempAngle degrees
          • Unit - Move (Triggering unit) instantly to TempPoint, facing TempAngle2 degrees
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: call RemoveLocation(udg_TempPoint2)
        • Else - Actions
          • Unit - Order (Triggering unit) to Stop
          • Set TempPlayerGroup = (All players matching ((Matching player) Equal to (Owner of (Triggering unit))))
          • Game - Display to TempPlayerGroup the text: This spell can only...
          • Custom script: call DestroyForce(udg_TempPlayerGroup)


Any help would be great, thanks :)
 

Ryushi

"I will stand, or I will fall. I will not sit."
Reaction score
59
Facing angles are reals, and reals don't leak, so no, the trigger doesn't leak.
 

inevit4ble

Well-Known Member
Reaction score
38
Looks good, but your second condition is checking if the target is in a unit group. That would mean you've set this group somewhere else. so either you destroyed it there and then this trigger will never fire or it will leak because that group is still sitting around.

You would need to set that group at the start of the trigger and destroy it at the end rather
 

ZakkWylde-

New Member
Reaction score
14
What exactly is the problem with an existing group: udg_IllusionistIllusions? Why would it "either be destroyed when it was set" or "leak"?

Does having units in a group cause leaks? (As far as I knew, it only leaks if you have no reference to whatever is in the group... and then you destroy the group[??]... otherwise, it is just taking up memory, as it should be. No?)
 

inevit4ble

Well-Known Member
Reaction score
38
I understood it as, groups etc that aren't destroyed (even when set to variables) leak. The whole reason we set them to variables is that we need to destroy them so a reference is required.

whats the difference between using an un-set group compared to setting a group and not destroying it? either way it sits around in the memory
 

vypur85

Hibernate
Reaction score
803
From the trigger, the Unit Group does not leak. It's just a dynamic unit group variable.

> ...we set them to variables is that we need to destroy them so a reference is required.
Yes. But setting a variable to a certain value does not mean it's a leak.
Code:
Set Point = Position of Someunit
Set Point2 = Point
Custom Script:  call RemoveLocation (udg_Point2)
Is the above Point variable leaking?
 

vypur85

Hibernate
Reaction score
803
Well you can try it out yourself.
Code:
Set Point = Position of Someunit
Set Point2 = Point
Custom Script:  call RemoveLocation (udg_Point2)
Special effect - Some special effect... at Point...
Special effect - Some special effect... at Point2...

Or think on another point of view. Use units instead.
Code:
Set Unit = Someunit
Set Unit2 = Unit
Custom script:  call RemoveUnit (udg_Unit)
Will Unit2 still be around in the map?
If it's not around in the map, does it leak?

Ps: RemoveUnit is typically 'Unit - Remove Unit' in GUI. Was just use the custom script to avoid confusion.
 

inevit4ble

Well-Known Member
Reaction score
38
Well...hmm

Ok, so I made this trigger for a test
Trigger:
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) types a chat message containing t as An exact match
    • Conditions
    • Actions
      • Set MyPoint = (Random point in (Playable map area))
      • Set MyPoint2 = (Random point in (Playable map area))
      • Unit - Create 1 Footman for Player 1 (Red) at MyPoint facing Default building facing degrees
      • Set MyUnit = (Last created unit)
      • Unit - Create 1 Footman for Player 1 (Red) at MyPoint2 facing Default building facing degrees
      • Set MyUnit2 = (Last created unit)
      • Custom script: call RemoveLocation(udg_MyPoint2)
      • Custom script: call RemoveUnit(udg_MyUnit2)
      • Game - Display to (All players) the text: (Name of MyUnit)
      • Game - Display to (All players) the text: (Name of MyUnit2)
      • Set MyX = (X of MyPoint)
      • Set MyX2 = (X of MyPoint2)
      • Set MyY = (Y of MyPoint)
      • Set MyY2 = (Y of MyPoint2)
      • Game - Display to (All players) the text: (String(MyX))
      • Game - Display to (All players) the text: (String(MyX2))
      • Game - Display to (All players) the text: (String(MyY))
      • Game - Display to (All players) the text: (String(MyY2))

The results I got was:
1 Footman Remianed, ofcourse they other has removed.
But both unit variables still retained the unit as they were not set == null so the handles remained
Point wise, MyPointX and Y both retained their values while MyPoint2 X and Y were 0. (Map Center) which is the default of a non-existant point.

So what I take away from this is:
Locations, Groups, Forces, SFX need to be destroyed
All handles need to be nulled
 

Smitty

Member
Reaction score
20
Looks good, but your second condition is checking if the target is in a unit group. That would mean you've set this group somewhere else. so either you destroyed it there and then this trigger will never fire or it will leak because that group is still sitting around.

You would need to set that group at the start of the trigger and destroy it at the end rather

There are 2 other triggers attached to this spell, one which adds an illusion to the unit group as soon as it's created, and another which removes it when it dies, the unit group is a constant rolling selection of units. Thanks for the help everyone, cleared up some minor niggling doubts :)
 

ZakkWylde-

New Member
Reaction score
14
From the trigger, the Unit Group does not leak. It's just a dynamic unit group variable.

> ...we set them to variables is that we need to destroy them so a reference is required.
Yes. But setting a variable to a certain value does not mean it's a leak.
Code:
Set Point = Position of Someunit
Set Point2 = Point
Custom Script:  call RemoveLocation (udg_Point2)
Is the above Point variable leaking?

Point wouldn't be "leaking," it would just be using memory. It would leak if you called this again without first removing Point, right?

As for the unit example, it seems slightly different, and it confuses me. I feel that Unit2 will be pointing to something non-existent, but still--it wouldn't actually leak unless you set Unit2 to something else without removing it...right? Or am I lost :p
 

vypur85

Hibernate
Reaction score
803
Both don't leak. I was just using Unit as an example because it's more of a tangible object as compared to Point, which you can't really see. Both are essentially the same concept.

Then again, this is based off my old knowledge. In the past, this was considered fine and not leaking.


> inevit4ble
Your test trigger is not similar with the trigger I posted.
 

ZakkWylde-

New Member
Reaction score
14
Both don't leak. ...

Unless you set them again without removing them, right?
If you set them to something else, then isn't that 'original' location (or unit) just sitting around in memory with no reference to it (i.e. leak?) ?
 

vypur85

Hibernate
Reaction score
803
That is why I used the Unit as example. By removing Unit2, do you think Unit still exist? If it doesn't exist, does it leak?

Leak occurs if you lose reference to a certain object. Both Unit and Unit2 are references to a single object. By removing either one, you have successfully remove the single object. So it doesn't leak.

(I believe in JASS, you'd need to null both the variables, but for GUI, it's fine.)
 
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