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

[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?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
When a unit dies it either is instantly removed (after death animation ofc) or it will make a corpse.
The corpse has a timer and when it expires, the corpse (aka the original unit) is removed from the game. All references to that unit have a null value after that.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
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