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

hashtables - clearing

Status
Not open for further replies.
Level 18
Joined
Jan 21, 2006
Messages
2,552
I suggest you always remove saved values from hashtables after you no longer need them.

JASS:
globals
    hashtable   hashData            = InitHashtable()
    timer       toGrab              = CreateTimer()             // This is just a random handle variable that we are going
                                                                // to "save" a unit to as an example.
endglobals


function FuncB takes nothing returns nothing
    local unit u = LoadUnitHandle(hashData, GetHandleId(toGrab), StringHash("Random Unit"))
    
    call RemoveUnit(u)
    call RemoveSavedHandle(hashData, GetHandleId(toGrab), StringHash("Random Unit"))
    
    set u = null
endfunction


function FuncA takes nothing returns nothing
    local unit u = CreateUnit(Player(0), 'hpea', 0, 0, 0)
    
    call SaveUnitHandle(hashData, GetHandleId(toGrab), StringHash("Random Unit"), u)
    set u = null
endfunction

I'm curious as to what happens when you save a null unit.
 
Level 12
Joined
Aug 22, 2008
Messages
911
No it does not, for example if you save locations in a Hashtable and then clear them it doesn't delete the leak because it just deleted the handle of the location, not the location itself. You'll need to delete the locations themselves to remove the leak.
 
Status
Not open for further replies.
Top