[Solved] A simple question about hashtables.

Status
Not open for further replies.
When you save a location in a hashtable, it doesn't make a copy. It just "points" to it.

So if you want to free a location, simply load it and remove it as usual:
  • Set TempLoc = (Load <Key> of <Key> in MyHashtable)
  • Custom script: call RemoveLocation(udg_TempLoc)
TempLoc isn't set to a new location--it is set to the exact same location you saved using "Hashtable - Save Point...". So when you save the location in your hashtable, you should not remove it until you load it later.
 
When you save a location in a hashtable, it doesn't make a copy. It just "points" to it.

So if you want to free a location, simply load it and remove it as usual:
  • Set TempLoc = (Load <Key> of <Key> in MyHashtable)
  • Custom script: call RemoveLocation(udg_TempLoc)
TempLoc isn't set to a new location--it is set to the exact same location you saved using "Hashtable - Save Point...". So when you save the location in your hashtable, you should not remove it until you load it later.

Thank you. +rep
 
Found this very useful post 6 years later :D
Just to clarify with an example:
1. I set a location on a variable. ObjectiveLoc = Center of Region,
2. I save ObjectiveLoc into some Units in a Hashtable. The Key is the unit itself.
4. I order those units to attack-move to point -> Getting the point from the hashtable with themselves as the key (not from the variable).
5. I Clear All Child Hashtables of those Units in Hashtable.
6. I remove the location of the variable. Call RemoveLocation(udg_ObjectiveLoc).

This leaves me with 0 leaks, correct?
 
Found this very useful post 6 years later :D
Just to clarify with an example:
1. I set a location on a variable. ObjectiveLoc = Center of Region,
2. I save ObjectiveLoc into some Units in a Hashtable. The Key is the unit itself.
4. I order those units to attack-move to point -> Getting the point from the hashtable with themselves as the key (not from the variable).
5. I Clear All Child Hashtables of those Units in Hashtable.
6. I remove the location of the variable. Call RemoveLocation(udg_ObjectiveLoc).

This leaves me with 0 leaks, correct?
If it goes like you described, 0 leaks. But if 1. can run again before 6. (and you don't load ObjectiveLoc from hashtable before clear child-hashtables), you might remove the wrong loc.
 
Status
Not open for further replies.
Back
Top