• 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.

[Trigger] GUI leak and jass script

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
hi everyone, happy new year eve,

i read bribe GUI tutorial,
wich tell that every GUI with () is actually a function call...
so in order to remove and clean trigger i used variable.

TempUnitArray[0] = killing unit
TempUnitType[0] = killing unit type
TempPlayerArray[0] = owner of killing unit
TempUnitArray[1] = dying unit
TempUnitType[1] = dying unit type
TempPlayerArray[1] = owner of dying unit

this should make trigger much more efficient, but since i use variable i should clean those variable at the end of trigger, when these are no more needed.

so i used:
custom script: set udg_TempUnitType[0] = null
custom script: set udg_TempUnitArray[0] = null
custom script: set udg_TempPlayerArray[0] = null

but when saving it read an error with "TempUnitType"
type unit cannot be nulled? do i still need to clean it?
should i use = no unit instead of = null ?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
The type of a unit is represented by an integer, not a handle, so you cannot null a number and do not have to. It is hardly necessary to nullify global variables in general because these are static and commonly reused -> they cannot cause a dynamic leak.

And I did not catch the connection to function calls you hinted.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
http://www.hiveworkshop.com/forums/...quick-tutorial-common-triggering-tips-190802/

i am not sure about function call, but he said that to detect leak in GUI, looking at the "(" ")"
the bracket () show where there is code generated, so the more () the more code generated, most of the time for nothing because variable can store value.

ex:
Event= unit die
i want to check how many rabbit player 1 has killed
variable integer KillRabbit[array]

unit die
unit = rabbit
set killrabbit[(player number of(owner of(killing unit)))]= killrabbit[(player number of (owner of (killing unit)))] + 1

--------------------------------------------------------------------------------------

what does it do?
it look into a function that detect wich unit has killed the trigerring unit of unit die event:
probably // GetDyingunit return Killing unit something
then it launch another function // Getplayerowner of that unit
then it launch another one // GetInteger that player number

--------------------------------------------------------------------------------------

all this is launched each time ((())) what for? just to give an integer
so it is better to do:

set integer TempInteger = (player number of (owner of (killing unit)))
and then do:
KillRabbit[TempInteger]= KillRabbit[TempInteger] + 1

here the function to retrieve the value were launched only once, and then stored into variable, and then every action in the trigger directly used the variable to access value, so no need to use function to retrieve those value.

but if i use a variable to store each unit, each time a unit die...
the variable will be over written many many time and leak a unit handle each time...
so i need to null it at the end of the trigger.


Thanks Almia and WaterKnight for the info
i forgot that unit type was actually an integer, and of course integer don't need to be nulled.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Nulling should only be applied to locals, I believe ?
While destroying should be applied to globals.

locals
  • Custom script: local unit caster = GetTriggerUnit()
  • Custom script: caster = null
globals
  • Set caster = (Triggering unit)
Meanhile, destroy vs null, is another different story - which I don't understand very clear about this, can anyone tell me this ?

  • Custom script: local location loc = GetUnitLoc(TriggerUnit())
  • Custom script: ???
Should I null the local or should I destroy it ?
Or should I do both ?
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
all this is launched each time ((())) what for? just to give an integer
so it is better to do:

set integer TempInteger = (player number of (owner of (killing unit)))
and then do:
KillRabbit[TempInteger]= KillRabbit[TempInteger] + 1

here the function to retrieve the value were launched only once, and then stored into variable, and then every action in the trigger directly used the variable to access value, so no need to use function to retrieve those value.

but if i use a variable to store each unit, each time a unit die...
the variable will be over written many many time and leak a unit handle each time...
so i need to null it at the end of the trigger.

The () thing in Bribe's tutorial is mostly used to point excessive function calls, not leaks. Using a global to store different units won't cause a leak.

  • Custom script: local location loc = GetUnitLoc(TriggerUnit())
  • Custom script: ???
Should I null the local or should I destroy it ?
Or should I do both ?

RemoveLocation and null it.
 
Status
Not open for further replies.
Top