• 🏆 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!

[Trigger] Set units still set when dead?

Status
Not open for further replies.
Level 30
Joined
Jul 23, 2009
Messages
1,029
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,233
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