• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

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