• 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.

[Solved] Location Leaks with Hashtables

Status
Not open for further replies.
Level 5
Joined
Jul 15, 2012
Messages
101
I would like to ask if i'm doing hashdab table leak cleans right?

so i picked some units, saving the location handle
  • Hashtable - Save Handle Of(Position of (Load (Key Picked Unit) of FS in hastablas)) as (Key Position of Randomly Picked Unit) of FS in hastablas
then
  • Set loc = (Load (Key Position) of FS in hastablas)
  • Custom script: call RemoveLocation(udg_loc)
and repeating this procedure for every point/group, seems messy but don't know any other way with hashtables
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
On top of that, one must also remove the mapping to the location inside the hashtable. Otherwise one leaks key value pairs in the hashtable even if the value is no longer valid. One can either remove a specific parent and child key, or all child keys for a single parent. One cannot remove all parent and all child keys due to an API bug, the function intended to do this physically destroys the hashtable rendering it inoperable.
 
Level 5
Joined
Jul 15, 2012
Messages
101
I suppose I should use
  • Hashtable - Clear all child hashtables of child (Key FS) in hastablas
Do note: If you are using Handle ID as a parent of some Hashtable and into that very same Hashtable you save other important things related to that unit (so you save them under handle ID as well), then clearing all children of Parent (Handle ID) from that hashtable will not be the best idea, because you will loose all children - that includes those that still hold meaningful and important data of that unit.
so let's say I want to keep the parent's (FS) child (Damage). After I clear all the childs it's gone. How do I delete only specific child's of a parent (FS)?
 
so let's say I want to keep the parent's (FS) child (Damage). After I clear all the childs it's gone. How do I delete only specific child's of a parent (FS)?
The needed functions to remove only one speicific childKey are not ported to GUI.

Therefore you need custom script using one of this natives.
JASS:
native  RemoveSavedInteger  takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedReal  takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedBoolean  takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedString  takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedHandle   takes hashtable table, integer parentKey, integer childKey returns nothing
GUI and jass use the given values in different order.

GUI: childKey parentKey hash
Jass: hash parentkey childkey

to remove a location one would need to use RemoveSavedHandle.
Write that into custom script, for <childKey> inser the child you wana removed.
JASS:
call RemoveSavedHandle(udg_hastablas, udg_FS, <childKey>)
 
Level 5
Joined
Jul 15, 2012
Messages
101
GUI and jass use the given values in different order.
Write that into custom script, for <childKey> inser the child you wana removed.
JASS:
call RemoveSavedHandle(udg_hastablas, udg_FS, <childKey>)
Thanks for that.
So it went from something like this

  • Unit - Move (Triggering unit) instantly to ((Position of (Picked unit)) offset by (0.00, 0.00)), facing (Position of (Picked unit))
to

  • Unit - Move (Load (Key Caster) of FS in hastablas) instantly to (Load (Key Pos of Rn Picked Unit) of FS in hastablas), facing (Load (Key Pos of Rn Picked Unit) of FS in hastablas)
  • Set loc = (Load (Key Pos of Rn Picked Unit) of FS in hastablas)
  • Custom script: call RemoveLocation(udg_loc)
  • Custom script: call RemoveSavedHandle(udg_hastablas, udg_FS, StringHashBJ("Pos of Rn Picked Unit"))
  • Set ug = (Load (Key Unit Group) of FS in hastablas)
  • Custom script: call DestroyGroup(udg_ug)
  • Custom script: call RemoveSavedHandle(udg_hastablas, udg_FS, StringHashBJ("Unit Group"))
  • Set loc = (Load (Key Position) of FS in hastablas)
  • Custom script: call RemoveLocation(udg_loc)
  • Custom script: call RemoveSavedHandle(udg_hastablas, udg_FS, StringHashBJ("Position"))
not experienced with vJazz but I hope the <childKey>'s are right. Is there a way to check if it doesn't exist and I indeed did delete the child or anything else?
 
With this natives one can ask the table if that parent - child holds a value.
JASS:
native  HaveSavedInteger takes hashtable table, integer parentKey, integer childKey returns boolean
native  HaveSavedReal takes hashtable table, integer parentKey, integer childKey returns boolean
native  HaveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns boolean
native  HaveSavedString  takes hashtable table, integer parentKey, integer childKey returns boolean
native  HaveSavedHandle takes hashtable table, integer parentKey, integer childKey returns boolean
 
Level 5
Joined
Jul 15, 2012
Messages
101
Not sure how to print it out to the screen if the boolean is true or false with jazz but found out you can find it out with triggers, thanks for information everyone.
 
Status
Not open for further replies.
Top