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

Does KillUnit(GetTriggerUnit()) Leak?

Status
Not open for further replies.
JASS:
function KillTriggerUnit takes nothing returns nothing
    local unit U=GetTriggerUnit()
    call KillUnit(U)
    set U=null
endfunction
Do I have to set unit U to null at the end of the function? I'm pretty sure I do. Also, do I even have to have the local variable or will only using call KillUnit(GetTriggerUnit()) work as well without leaking?

This function is used in a trigger's condition if it matters.
 
For any handle that's destroyed you have to null all references (locals, globals) to it or else it will leak.

Also, killing the unit doesn't remove it so yeah it does leak.

EDIT: I ran some more tests and apparently when the unit decays it's removed, however there's still that leak you can't get rid of.

My previous tests were invalid because I was checking the handle id of a killed unit.

JASS:
//So basically
local unit u = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
call BJDebugMsg(I2S(GetHandleId(u)))
call BJDebugMsg(I2S(GetUnitTypeId(u)))
call RemoveUnit(u)
call TriggerSleepAction(0)
call BJDebugMsg(I2S(GetUnitTypeId(u))) // displays 0
call BJDebugMsg(I2S(GetHandleId(u))) // should display same thing no matter how much time has passed
 
Last edited:
Level 19
Joined
Mar 18, 2012
Messages
1,716
To summarize it for you
a) declared local and global unit variables should be nulled once you are done with them.
b) call KillUnit(GetTriggerUnit()) does not leak per se and can be used savely.
c) however every removed (decayed or removed) unit leaves a very small leak behind, send complains to blizzard.

Aslong as you are not spamming tousands of units it shouldn't be a problem at all.
 
Status
Not open for further replies.
Top