hashtables - clearing

Status
Not open for further replies.
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.
 
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.
Back
Top