• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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,229
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