• 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] Set units still set when dead?

Status
Not open for further replies.
Level 30
Joined
Jul 23, 2009
Messages
1,033
If I set a unit to a variable and the unit dies, will the unit still be saved in the variable until cleared?

For example I set unit X as TheUnit. TheUnit dies and 5 minutes later in the game I have a trigger that uses TheUnit's unit type as a reference, will the information for it still be available? Or upon TheUnit's death do I need to declare this information and save it for later use manually?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
The unit's handle will not be recycled until you re-assign all variables referencing it. This is because a removed unit does not null all referencing variables, instead it invalidates the handle so that it references nothing. The handle can only be safely recycled once all references to it have been re-assigned. The game does this by giving each handle a reference counter and incrementing/decrementing it on assignment/reassignment.

It is important to note that a serious bug with handles declared by the keyword "local" can cause permanent reference leaks. When the function returns it does not decrement the handle reference counter so prevents the handle from ever being recycled. The solution is to manually null the local before function return so that the reference counter is correctly decremented. This does not affect local handles declared as arguments.

Several BJs used by GUI suffer from this. Most notable is "PolledWait" or "Wait game time" which leaks a handle used for it's timer.
 
Status
Not open for further replies.
Top