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

[General] (hashtable question, gui) Will setting a new value in a hashtable cause a leak

Status
Not open for further replies.
Level 3
Joined
May 5, 2007
Messages
21
Hello, was wondering when I need to clear an hashtable?

for example:

lets assume (Key cd) of (Key (Picked unit)) in AI_hashtable in the trigger under is set to 0.

  • Set temp_real = ((Load (Key cd) of (Key (Picked unit)) from AI_hashtable) + 0.10)
  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in AI_hashtable
  • Hashtable - Save temp_real as (Key cd) of (Key (Picked unit)) in AI_hashtable
would the "Hashtable - Clear all child hashtables of child (Key (Picked unit)) in AI_hashtable" be needed? or would simply skipping that part work just fine?

edit: shit, this should probably been in the Triggers & Scripts area, sorry
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
You flush child hashtables when the data stored will either no longer be needed or will become inaccessible (in a sense) and won't be overwritten. If you do not do so this data will accumulate in the hashtable slowly consuming more memory like a series of memory leaks. In this case whenever you need to stop tracking cd on that particular picked unit you should flush its children. This is usually when such a unit dies (but can't be revived) or is about to be removed from the map, or a (if this is a spell) when the spell ends its effect(s).
 
Level 3
Joined
May 5, 2007
Messages
21
You flush child hashtables when the data stored will either no longer be needed or will become inaccessible (in a sense) and won't be overwritten. If you do not do so this data will accumulate in the hashtable slowly consuming more memory like a series of memory leaks. In this case whenever you need to stop tracking cd on that particular picked unit you should flush its children. This is usually when such a unit dies (but can't be revived) or is about to be removed from the map, or a (if this is a spell) when the spell ends its effect(s).

hmm.. so if this is for my "ai" during a duel, i shouldn't need to clear the hashtable until after the duel end?

Also does that mean I should clear "parent" and not just "child" for stuff like spells when the effects ends and none is currently casting the spell effect?
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
What you’re saying about the duel sounds correct.

As for clearing it depends on your methodology. To be clear: you can either flush all children of a particular parent or you can flush all children of all parents. If you’re using a different hashtable for each ‘thing’ you need one for then you can just clear the whole table. But if you are doing multiple things (say, spells) per hashtable then you would likely only want to clear specific data otherwise you might delete something else that another trigger/function is using.
 
Status
Not open for further replies.
Top